Corner JS promise in app.run ()

I am working on an angularJs and typescript project. I have to make a synchronous http call and get some data from the server before starting the client application and loading the user interface. I search the Internet and see how everyone talks about the promise, well, well, why not. So I use the promise (make $ http call and use $ q to return the promise) in my app.run (). Maybe I’m not losing anything because it doesn’t work at all. Angular run app.config (), then app.run (), ... But Angular did not wait for app.config () to complete before running app.run (). So, my first promise runs in app.run (), and before it allows Angular to try to instantiate the controller ... I don't want to create a new httpSynchronous service call, but I have no other ideas.

+6
source share
1 answer

Angular does not support asynchronous actions in .config and .run . If you want to postpone your application, there are two ways:

  • The first one is to delay the entire application using angular.bootstrap () to manually launch it. But everything you do is outside of angular, so you have no access to anything but vanilla JavaScript.
  • The second way is to use the resolution property of your routes. If you use a router, such as an Angular route segment or ui router , you can define the top route / state with permission that will be allowed when your application loads (and if you force a full reload of your route).
+14
source

Source: https://habr.com/ru/post/982744/


All Articles