为嵌入式视图传递 `params` ui-router
Pass `params` for embedded view ui-router
我正在使用 UI-Router 构建应用程序。我需要在一页上有多个视图,所以我使用抽象状态。我试图将参数 "isEmbedded" 传递给 owner
视图,但不幸的是它不起作用。我想知道是否是因为我将它传递给子视图。当我在ownerCtrl
中console.log($stateParams)
时,不显示isEmbedded
参数。知道为什么吗?
.state('dog', {
url: "",
parent: "dogAbstract",
views: {
"owner": {
templateUrl: 'client/people/views/owner.ng.html',
controller: 'ownerCtrl',
params:{
isEmbedded:true
}
}
}
})
P.S。我从这个问题中得到了使用 params
的想法:
虽然 $stateParams 属于状态,但我们可以对视图使用特殊解析:
...
views: {
"owner": {
templateUrl: 'client/people/views/owner.ng.html',
controller: 'ownerCtrl',
resolve:{
isEmbedded: function() { return true},
}
}
}
我用这两个子状态创建了an example here
.state('parent.child', {
url: "/child",
templateUrl: 'tpl.html',
controller: 'ChildCtrl',
resolve: {
isEmbedded: function() { return false},
}
})
.state('parent.child2', {
url: "/child2",
templateUrl: 'tpl.html',
controller: 'ChildCtrl',
resolve: {
isEmbedded: function() { return true},
}
})
并且控制器可以使用它:
.controller('ChildCtrl', ['$scope', 'isEmbedded',
function ($scope, isEmbedded) {
console.log(isEmbedded)
}
])
检查一下here
我正在使用 UI-Router 构建应用程序。我需要在一页上有多个视图,所以我使用抽象状态。我试图将参数 "isEmbedded" 传递给 owner
视图,但不幸的是它不起作用。我想知道是否是因为我将它传递给子视图。当我在ownerCtrl
中console.log($stateParams)
时,不显示isEmbedded
参数。知道为什么吗?
.state('dog', {
url: "",
parent: "dogAbstract",
views: {
"owner": {
templateUrl: 'client/people/views/owner.ng.html',
controller: 'ownerCtrl',
params:{
isEmbedded:true
}
}
}
})
P.S。我从这个问题中得到了使用 params
的想法:
虽然 $stateParams 属于状态,但我们可以对视图使用特殊解析:
...
views: {
"owner": {
templateUrl: 'client/people/views/owner.ng.html',
controller: 'ownerCtrl',
resolve:{
isEmbedded: function() { return true},
}
}
}
我用这两个子状态创建了an example here
.state('parent.child', {
url: "/child",
templateUrl: 'tpl.html',
controller: 'ChildCtrl',
resolve: {
isEmbedded: function() { return false},
}
})
.state('parent.child2', {
url: "/child2",
templateUrl: 'tpl.html',
controller: 'ChildCtrl',
resolve: {
isEmbedded: function() { return true},
}
})
并且控制器可以使用它:
.controller('ChildCtrl', ['$scope', 'isEmbedded',
function ($scope, isEmbedded) {
console.log(isEmbedded)
}
])
检查一下here