[英]Inheriting parameters with nested views in Angular UI-router?
我試圖通過狀態子級在父視圖中設置嵌套視圖加載,但是我不確定是否要采用正確的方法。
到目前為止,我有:
$stateProvider
.state('splash', {
url: '/splash',
templateUrl: 'system/templates/splash.html',
controller: ""
}).state('home', {
url: '/',
templateUrl: 'system/templates/home.html',
controller: ""
}).state('user', {
url: '/user/:user?',
templateUrl: 'system/templates/user.html',
controller: "userController"
}).state('user.data', {
views: {
"@vdata" : {
templateUrl: 'system/templates/user.html',
controller: "userController"
}
}
})
“用戶”父狀態接收到:用戶? 正確的方法,但是當我嘗試通過$ state.transitionTo();導航時,我得到了響應
參數值對於狀態“ user.data”無效。 我有該模式的未命名視圖
<div ui-view></div>
設置為父級。 然后嵌套在用戶模板中,我有一個名為“ vdata”的用戶界面視圖。 根據文檔,如果我以@vdata為目標,則請求的頁面應該在那里加載。
如何獲取嵌套視圖以從父視圖繼承參數?
使用resolve
並在控制器上注入用戶。 解析的引用在父子狀態之間共享。
$stateProvider
.state('splash', {
url: '/splash',
templateUrl: 'system/templates/splash.html',
controller: ""
}).state('home', {
url: '/',
templateUrl: 'system/templates/home.html',
controller: ""
}).state('user', {
url: '/user/:user?',
templateUrl: 'system/templates/user.html',
controller: "userController",
resolve:{
user: function($stateparams){
return $stateParms.user;
}
}
....
在usercontroller上注入user
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.