gpt4 book ai didi

angularjs - ui-router 嵌套 View 访问多个 Controller

转载 作者:行者123 更新时间:2023-12-03 08:11:39 25 4
gpt4 key购买 nike

使用 ui-router,一个州的任何 child 和孙子都可以访问他们的 parent 和祖 parent 的 Controller 吗?

因此,例如一个 .state(resources.resource.rates) .rate 状态 Controller 可以访问资源和资源(都有自己的 Controller )中的 $scope.objects 对吗?

假设我有一个 html 设置,其中所有内容都是带有 ui-view="content2"的资源中的嵌套 View 。但是,我在资源中有另一个页面,称为 rate 我想在与资源相同的嵌套 View 中打开,但也可以访问资源 Controller 。

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

我 View 中的 ng-href 链接到/resources/{{resource.Id}}/rates,但没有打开资源 ui-view 中的费率页面。

所以我尝试的是将 View 设置为 content2@resources 像这样
views:{
"content2@resources":{
templateUrl: 'templates/rates.html',
controller: 'CreateRatesCtrl'
}
}

这在某种意义上是有效的,即 html 现在在资源 ui-view 中填充 rate.html,并使用 ng-href 作为 resources/{{resource.Id}}/rates 但不幸的是我只能访问资源范围对象。我有一个资源 Controller 需要的 resourceId。在这种情况下,设置 content2@resources 是否将我的范围访问限制为仅资源 Controller ?如果是这样,我怎样才能做到这一点,以便我也可以访问资源 Controller ?

最佳答案

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



这应该足以了解状态和/或 View 的嵌套给予和不给予你什么。

关于angularjs - ui-router 嵌套 View 访问多个 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25275154/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com