在更新父ui.router国决心对象 [英] Updating resolved objects in ui.router parent states

查看:153
本文介绍了在更新父ui.router国决心对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是双重的:

1 - 我有一个父状态,并使用ui.router几个子状态,有一个对象(存储在MongoDB中),它需要所有国家,但它得到所有国家更新。在这种情况下是否有意义使用父状态的决心选项来填充对象?

1 - I have a parent state and several child states using ui.router, there's one object (stored in mongodb) that is need in all states, but it gets updated by all states. In this scenario does it make sense to use the parent state's resolve option to populate the object?

2 - 如果是做正确的方法,我怎么能更新参考从每一个州到该对象(由ui.router创建的模拟服务喷油器)

2 - If this is the proper way to do this, how can I update that "reference" (the mock service injector created by the ui.router) to that object from every state.

要帮助解释他的想法(很多code的的ommited)

To help in explain he's a example of the idea (lot's of code ommited)

.state('parent',resolve:{objectX:return x.promise;},...);

.controller('childstateCtrl',$scope,objectX){
    $scope.data.objectX = objectX;
    $scope.someEvent =function(){ 
    // something updates objectX on the scope
    }
}

.controller('otherChildCtrl',$scope,objectX){
    // how to get the updated objectX?
}

在此先感谢

推荐答案

不完全知道如果我能看到的是问题...但如果​​你正在寻找一种方式,如何共享访问更新的参考,它应该很容易。有为例

Not fully sure if I can see where is the issue... but if you are searching for a way how to share access to updated reference, it should be easy. There is an example

让我们这些状态

$stateProvider
  .state('root', {
    abstract: true,
    template: '<div ui-view></div>',
    resolve: {objectX : function() { return {x : 'x', y : 'y'};}},
    controller: 'rootController',
  })
  .state('home', {
    parent: "root",
    url: '/home',
    templateUrl: 'tpl.example.html',
  })
  .state('search', {
    parent: "root",
    url: '/search',
    templateUrl: 'tpl.example.html',
  })
  .state('index', {
    parent: "root", 
    url: '/index',
    templateUrl: 'tpl.example.html',
  })

只有一个控制器工作(为根状态):

Working with only one controller (for a root state):

.controller('rootController', function($scope, objectX){
  $scope.data = { objectX: objectX };
})

和在这个例子中,这是共享的模板:

And for this example, this is shared template:

<div>
  <h3>{{state.current.name}}</3>

  x <input ng-model="data.objectX.x"/>
  y <input ng-model="data.objectX.y"/>
</div>

因此​​,在这种情况下,父(根)注入一个对象数据到$范围。这参考,然后以所继承此处描述:

So, in this scenario, parent (root) has injected an object data into $scope. That reference is then inherit as described here:

检查行动那个例子这里。如果你需要更多的细节(比上面的链接,看看这个 Q&安培; A

Check that example in action here. If you need more details (than in the link above, check this Q&A)

这篇关于在更新父ui.router国决心对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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