状态 angularjs $stateProvider 不传递参数 [英] States angularjs $stateProvider not passing arguments
问题描述
我得到了一个使用标准 $routeProvider 进行路由的当前 angularjs 应用程序.我打算将应用程序的一部分 $stateProvider 用于向导.
I got a current angularjs application using the standard $routeProvider for routing. I intend to use a part of the application the $stateProvider for a wizard.
我像这样声明了一个父状态Modal"和一个子状态editClient":
I declared a parent state 'Modal' and a child state 'editClient' like this:
$stateProvider.state('Modal', {
views: {
'modal': {
templateUrl: '*urlHere*',
controller: '*controllerHere'
}
},
abstract: true
});
$stateProvider.state('Modal.editClient', {
views: {
"modal": {
url: '/editClient/:id',
templateUrl: '*templateHere*',
controller: '*controllerHere*'
}
}
});
在我的控制器中,我调用:
In my controller I call:
$state.go('Modal.editClient', { id: 1});
然而 $stateParams 是空的.怎么来的?
Yet $stateParams is empty. How come?
我使用的是 angular-ui-router 版本 0.2.15 和 angularjs 1.2.25.目前无法更新到更高的 angularjs 版本.
I'm using angular-ui-router version 0.2.15 and angularjs 1.2.25. Updating to a higher angularjs version is not possible at the moment.
更新
我也试过:
$stateProvider.state('Modal.editClient', {
views: {
"modal": {
params: {
'id' : 0
},
templateUrl: '*templateUrlHere*',
controller: '*controllerHere*'
}
}
});
推荐答案
您没有在定义状态的状态中传递参数,您需要做这样的事情.
You are not passing argument in state where you are defining your states you need to do something like this.
$stateProvider.state('Modal', {
views: {
'modal': {
templateUrl: '*urlHere*',
controller: '*controllerHere'
}
},
abstract: true
});
$stateProvider.state('Modal.editClient', {
params: {
'id': 0
},
views: {
"modal": {
url: '/editClient/:id',
templateUrl: '*templateHere*',
controller: '*controllerHere*'
}
}
});
这篇关于状态 angularjs $stateProvider 不传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!