angularjs – ui-router嵌套视图访问多个控制器

前端之家收集整理的这篇文章主要介绍了angularjs – ui-router嵌套视图访问多个控制器前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_301_3@
使用ui-router,州的任何子孙都可以访问他们的父母和祖父母控制器吗?

所以例如.state(resources.resource.rates).rate状态控制器可以访问资源和资源中的$scope.objects(它们都有自己的控制器)吗?

在假设我有一个html设置,其中一切都是资源内的嵌套视图与ui-view =“content2”.但是我在资源中有另一个页面称为费率我想在与资源相同的嵌套视图中打开,但也可以访问资源控制器.

.state('resources.resource.rates',{
    url: '/rates',views:{
        "content2":{
            templateUrl: 'templates/rates.html',controller: 'CreateRatesCtrl'
        }
    }   
})

我的视图中的ng-href链接到/resources/{{resource.Id}}/rates但不打开资源ui-view中的rates页面.

所以我尝试将视图设置为content2 @ resources,就像这样

views:{
        "content2@resources":{
            templateUrl: 'templates/rates.html',controller: 'CreateRatesCtrl'
      }
}

这是因为html现在在资源ui-view中填充rates.html,并且ng-href作为resources / {{resource.Id}} / rates填充,但不幸的是我只能访问资源范围对象.我有一个资源控制器所需的resourceId.在这种情况下,设置content2 @ resources是否限制我的范围只能访问资源控制器?如果是这样我怎么能这样做,所以我也可以访问资源控制器?

解决方法

引自 ui-router wiki :

Keep in mind that scope properties only inherit down the state chain if the views of your states are nested. Inheritance of scope properties has nothing to do with the nesting of your states and everything to do with the nesting of your views (templates).

这应该足以理解状态和/或视图的嵌套给出了什么,而不是给你.

@H_301_3@

猜你在找的Angularjs相关文章