是我的$ stateProvider:
$stateProvider
.state('home', {
url : '/',
templateUrl : '/admindesktop/templates/main/',
controller : 'AdminDesktopMainController'
}).state('company', {
url : '/company',
templateUrl : '/admindesktop/templates/grid/',
controller : 'CompanyGridController'
}).state('company.detail', {
url : '/{id:\d+}', //id is
templateUrl : '/admindesktop/templates/company/detail/',
controller : 'CompanyDetailController'
});
它适用于'公司'状态(我使用ui-sref),但此代码不起作用(从'公司'状态调用):
$state.go('.detail', {
id: $scope.selectedItem.id //selectedItem and id is defined
});
我从StackOverflow上阅读官方文档和答案,但我找不到解决方案。我不能使用ui-sref,我使用ui-grid,并在从表中选择一行进行编辑后打开新状态。
我做错了什么?
总是有效的是完整的状态定义:
// instead of this
// $state.go('.detail', {
// use this
$state.go('company.detail', {
id: $scope.selectedItem.id //selectedItem and id is defined
});
在doc there are defined these options,但他们依赖于CURRENT状态:
串起来 绝对州名或相对州路径。一些例子:
- $ state.go('contact.detail') - 将转到contact.detail状态
- $ state.go('^') - 将转到父状态
- $ state.go('^ .sibling') - 将进入兄弟姐妹州
- $ state.go('。child.grandchild') - 将去孙子州
我的错误是正则表达式,真的:
.state('company.detail', {
url : '/{id:\d*}',
templateUrl : '/admindesktop/templates/company/detail/',
controller : 'CompanyDetailController'
})
{id:\ d *}有效(整数id)。