[英]angular ui-router - nested controller - parent controller is initiated twice if child controller is in the same state
.state('home', {
url: '/home',
views: {
'main': {
templateUrl: './main.html',
controller: 'mainController'
},
'parent@home': {
templateUrl: './parent.html',
controller: 'parentController'
},
'child@home':{
templateUrl: './child.html',
controller: 'childController'
},
'otherPage@home': {
templateUrl: './other-page.html',
controller: 'otherController'
}
}
})
在parent.html中,我有子視圖。 基本上,父控制器(parentController)在此設置中啟動了兩次。 如果我刪除child @ home狀態,則parentController僅啟動一次。 我在做什么錯,有沒有更好的方法來定義這些狀態?
<div class="maincontent" ui-view="main"></div>
<div class="maincontent container-fluid" ui-view="parent"></div>
<div class="maincontent container-fluid" ui-view="otherPage"></div>
<div ui-view="child"></div>
像這樣重新定義狀態:
.state('home', {
url: '/home',
views: {
'': {
templateUrl: './main.html',
controller: 'mainController'
},
'parent@home': {
templateUrl: './parent.html',
controller: 'parentController'
},
'child@home':{
templateUrl: './child.html',
controller: 'childController'
},
'otherPage@home': {
templateUrl: './other-page.html',
controller: 'otherController'
}
}
})
根據我的理解,帶有空鍵的視圖將被加載為原始狀態的默認視圖。
這樣,您的main.html
模板將包含指向其他ui-views
指針,就像您對parent
和otherPage
所做的otherPage
。
我無法進行測試,因為我不在開發PC上,但我認為它應該可以工作,因為它是我的幾個AngularJS項目遵循的格式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.