UI路由器嵌套视图访问多个控制器多个、嵌套、视图、路由器

2023-09-14 00:23:54 作者:始于心动,止于枯骨

与UI的路由器,一个国家的任何子女以及孙子有他们的父母和祖父母控制器访问是否正确?

with ui-router, any child and grandchild of a state has access to their parent and grandparents controller correct?

所以,例如.STATE(resources.resource.rates)的.rate状态控制器有权访问资源和资源$ scope.objects(这都有自己的控制器)吧?

So for example a .state(resources.resource.rates) the .rate state controller has access to the $scope.objects in resource and resources (which all have their own controllers) right?

在presumption我有一个HTML建立的一切是一个用户界面视图=内容2的资源中嵌套的视图。不过,我有资源称为率中的另一个页面,我想在同一个嵌套的视图资源开拓也获得对资源的访问控制,以及

On the presumption I have a html set up where everything is a nested view within resources with a ui-view="content2". However I have another page within resource called rates I would like to open up in the same nested view as resources but also gets access to the resource controller as well.

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

我的NG-的href在我看来链接到/resources/{{resource.Id}}/rates,但开不起来的资源UI视图行情页。

my ng-href in my view links to the /resources/{{resource.Id}}/rates but doesn't open up the rates page in the resources ui-view.

所以我试着在设置视图内容2 @资源,像这样

so what I tried was setting the view to content2@resources like so

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

这个作品在这个意义上,现在的HTML中填充的资源UI的视图,并在NG-HREF作为资源/ {{resource.Id}} /率rates.html可惜我只能访问的资源范围的对象。我有一个RESOURCEID,我从资源控制的需要。不设置内容2 @资源限制为仅在这种情况下,资源控制器我的范围存取?如果是的话我怎么能让它,所以我可以访问资源控制器呢?

This works in the sense that the html now populates the rates.html in the resources ui-view and with the ng-href as resources/{{resource.Id}}/rates but unfortunately I only have access to the resources scope objects. I have a resourceId that I need from the resource controller. Does setting content2@resources limit my scope access to only the resources controller in this case? If so how can I make it so I can get access to the resource controller as well?

推荐答案

从 UI路由器维基:

记住,如果你的国家的意见是嵌套作用域属性只继承下来的状态链。作用域属性的继承无关,与你的国家的嵌套和一切与你的视图(模板)嵌套。

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).

这应该是足够的了解美国和/或意见给,不给你的。什么样的嵌套

This should be enough to understand what nesting of states and/or views gives and doesn't give you.