ui-router: Parent's resolve not called when state changes

23t*_*tux 2 javascript angularjs angular-ui-router

in ui-router, when a state changes it should call all its parent resolves. This works the first time a state changes. But for the second time, the resolves of the parent aren't called (maybe because they already resolved before).

This is the state configuration

var app = angular.module('plunker', ['ui.router']);

app.config(function($stateProvider) {
  $stateProvider
  .state('root', {
    abstract: true,
    resolve: {
      preloadData: function() {
        console.log("preloadData");
        return true;
      }
    }
  })
  .state('root.home', {
    resolve: {
      test: function() {
        console.log('Home')
        return true;
      }
    }
  })
  .state('root.login', {
    resolve: {
      test: function() {
        console.log('Login')
        return true;
      }
    }
  });
});
Run Code Online (Sandbox Code Playgroud)

And here is the plnkr http://plnkr.co/edit/rMVbxErZyStt97JifJlj. Open the dev console and click on the buttons. You see that preloadData is only called the first time a state changes. For future state changes it is not called.

Is this behaviour intended / normal? Is there a way to force a call to the parent's resolves on every state change?

New*_*Dev 5

The "resolves" of a particular state run when you go to that state (or one of its descendants) from a "outsider" state - i.e. a state outside of the hierarchy tree of the state in question. Then, navigation between its descendants and itself does not re-run the "resolves" and the controllers.

In other words, given the following example of state hierarchy:

     A     B
    /     /
   AA    C
        / \
       C1 C2
Run Code Online (Sandbox Code Playgroud)

然后,从 A 切换到 B 将运行 B 的控制器并“解析”,因为 A 在 B 树之外。然后切换到 C(或 C1 或 C2),然后再切换回 B,不会重新运行 B 的解析。

如果您随后切换回 A(或 AA),则 A 将执行解析。