UI-Router:父状态和子状态的顺序解析 [英] UI-Router: sequential resolve of parent and child states

查看:125
本文介绍了UI-Router:父状态和子状态的顺序解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个抽象状态 parent.child ,还有一个可激活状态州 parent.child.grand

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

我想 parent.child.grand 执行其解析之前承诺解决。为什么?因为 parent.grand.child 中需要来自 parent 的解析中的ajax请求的某些数据。

I want parent to be promise resolved before parent.child.grand gets its resolves executed. Why? Because a certain data which comes from the ajax request in the resolve from parent is required inparent.grand.child.

这是一个要点

是否有可能顺序将父级的承诺链接到子状态而不使用控制器?

Is it possible to sequentially chain the promises of parent to children states without using controllers ?

parent resolve start - >完成ajax请求 - >解析promise - > parent.child.grand resolve start - >完成ajax请求 - >解决承诺)

(parent resolve start -> finish ajax request -> resolve promise -> parent.child.grand resolve start -> finish ajax request -> resolve 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.

以下是示例:

    $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'
        })

而且你不必将resA注入儿童控制器。

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

这篇关于UI-Router:父状态和子状态的顺序解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆