这些是我的州定义:
$stateProvider
.state('schoolyears', {
url: '/schoolyears',
templateUrl: '../views/schoolyears.html',
controller: 'SchoolyearsController'
})
.state('schoolyears.selected', {
url: '/:schoolyearId'
})
在SchoolyearsController内部,当数据网格中的行选择发生变化时,我调用$ state.go:
$scope.myOptions = {
data: 'myData',
multiSelect: false,
selectedItems: [],
afterSelectionChange: function (rowItem) {
if (rowItem.selected) {
$state.go('schoolyears.selected({ schoolyearId:' + rowItem.entity.schoolyearId + '}');
}
}};
网址中没有任何内容,因为在我的浏览器控制台中出现此错误:
Error: Could not resolve 'schoolyears.selected({ schoolyearId:43}' from state 'schoolyears'
我想要的是网址更改为:
/#/schoolyears/43
为什么我不能更改网址?
答案 0 :(得分:8)
在SchoolyearsController内部更改:
afterSelectionChange: function (rowItem) {
if (rowItem.selected) {
$state.go('schoolyears.selected({ schoolyearId:' + rowItem.entity.schoolyearId + '}');
}
}};
为:
afterSelectionChange: function (rowItem) {
if (rowItem.selected) {
$state.go('schoolyears.selected',{ schoolyearId: rowItem.entity.schoolyearId });
}
}};
在此实例中,$state.go
可以使用两个参数重载,有关详细信息,请参阅api reference