简体   繁体   English

UI-Router:父状态和子状态的顺序解析

[英]UI-Router: sequential resolve of parent and child states

I have two abstract states parent and parent.child , and an activateable state parent.child.grand . 我有两个抽象状态parentparent.child ,以及一个可激活状态parent.child.grand

I want parent to be promise resolved before parent.child.grand gets its resolves executed. 我想parent承诺解决之前parent.child.grand获取其做出决议执行。 Why? 为什么? Because a certain data which comes from the ajax request in the resolve from parent is required in parent.grand.child . 因为parent.grand.child需要来自parent解析的ajax请求的某些数据。

Here's a gist 这是一个要点

Is it possible to sequentially chain the promises of parent to children states without using controllers ? 是否可以在不使用控制器的情况下顺序将父级的承诺链接到子状态?

( parent resolve start -> finish ajax request -> resolve promise -> parent.child.grand resolve start -> finish ajax request -> resolve promise) parent解析开始 - >完成ajax请求 - >解析promise - > parent.child.grand解析start - >完成ajax请求 - >解析promise

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. 如果要在实例化子项之前等待解析promise,则必须将解析键注入子状态。

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. 而且您不必将resA注入子控制器。

If you add auth to the dependency injection of your grandchild resolve, ui-router will resolve it prior to the grandchild resolve. 如果将auth添加到孙子解析的依赖注入中,ui-router将在孙子解析之前解析它。

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

Hope that makes sense. 希望有道理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM