UI-Router: sequential resolve of parent and child states

后端 未结 2 1334
说谎
说谎 2021-02-05 12:26

I have two abstract states parent and parent.child, and an activateable state parent.child.grand.

I want pa

相关标签:
2条回答
  • 2021-02-05 13:22

    I've seen a few answers for this but it still wasn't entirely clear without an example. The docs say:

    The resolve keys MUST be injected into the child states if you want to wait for the promises to be resolved before instantiating the children.

    Here's the example:

        $stateProvider.state('parent', {
              resolve:{
                 resA:  function(){
                    return {'value': 'A'};
                 }
              },
              controller: 'parentCtrl'
           })
           .state('parent.child', {
              resolve:{
                 // Adding resA as an argument here makes it so that this child state's resB resolve
                 // function is not run until the parent state's resA resolve function is completed.
                 resB: function(resA){
                    return {'value': resA.value + 'B'};
                 }
              }
              controller: 'childCtrl'
            })
    

    And you don't have to inject resA into the child controller.

    0 讨论(0)
  • 2021-02-05 13:28

    If you add auth to the dependency injection of your grandchild resolve, ui-router will resolve it prior to the grandchild resolve.

    ['authsrv', 'auth', function(authsrv, auth){}]

    Hope that makes sense.

    0 讨论(0)
提交回复
热议问题