admin管理员组

文章数量:1285835

Thanks to this answer AngularJS app.run() documentation? i can see the order in which modules are ran by Angular, my question is:

if I have:

app.config(function () {
    $routeProvider.when('/', {
        ....
        resolve: {
            // something to resolve
        }
    });
});

app.run(function () {
    // something to run
});

Will run() be executed before the routeProvider resolve:{} is resolved?

Thanks to this answer AngularJS app.run() documentation? i can see the order in which modules are ran by Angular, my question is:

if I have:

app.config(function () {
    $routeProvider.when('/', {
        ....
        resolve: {
            // something to resolve
        }
    });
});

app.run(function () {
    // something to run
});

Will run() be executed before the routeProvider resolve:{} is resolved?

Share Improve this question edited May 23, 2017 at 12:17 CommunityBot 11 silver badge asked Jun 16, 2014 at 17:30 Filippo orettiFilippo oretti 49.8k96 gold badges229 silver badges351 bronze badges 1
  • 2 someone playing with -1 button like a kid – Filippo oretti Commented Jun 17, 2014 at 15:07
Add a comment  | 

1 Answer 1

Reset to default 28

At least in my experiments, yes the resolve is run after app.run.

In this jsfiddle you can see the calling order I got was:

  1. app config
  2. app run
  3. directive setup
  4. directive compile
  5. app controller
  6. directive link
  7. ** Data resolve called **
  8. new route's controller

As you can see in the fiddle, I checked this by using a console.log function as the value of a property of the object handed to resolve:

resolve: {
            data: function() {
              console.log('Data resolve called');
            }
         }

You can use this same approach in your code to check when routeProvider begins checking the dependencies.

本文标签: javascriptAngular jsresolve and run() order of executionStack Overflow