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

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

问题描述

我有两个抽象状态parentparent.child,以及一个可激活状态parent.child.grand.

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

我希望 parentparent.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 解析开始-> 完成ajax 请求-> 解析promise -> parent.child.grand 解析开始-> 完成ajax 请求-> 解析promise)

(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天全站免登陆