Wottensprels
Wottensprels

Reputation: 3327

Angular - Ensure that app.run() has executed

I am using app.run() to fire a method that initializes a user session.

Now I was just adding another method to app.run() and discovered that some method in the routeProviders resolve fired asynchronously, overlapping with the session initialisation and therefore crashing the application.

How can I ensure that app.run() has executed before firing anything route related?

Upvotes: 1

Views: 60

Answers (1)

sam rodrigues
sam rodrigues

Reputation: 580

Are you trying to do somthin async in your app.run() ?? this may help

angular.element(document).ready(
    function() {
        var initInjector = angular.injector(['ng']);
        var $http = initInjector.get('$http');
        $http.get('/test.json').then(
            function (response) {
               var x = response.data;

               angular.bootstrap(document, ['App']);
            }
        );
    }
);

Upvotes: 1

Related Questions