如何$ state.go()

Dun*_*xim 7 angularjs angular-ui-router

是我的$ 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'
});
Run Code Online (Sandbox Code Playgroud)

它适用于'公司'状态(我使用ui-sref),但此代码不起作用(从'公司'状态调用):

$state.go('.detail', {
    id: $scope.selectedItem.id //selectedItem and id is defined
});
Run Code Online (Sandbox Code Playgroud)

我从StackOverflow上阅读官方文档和答案,但我找不到解决方案.我不能使用ui-sref,我使用ui-grid,并在从表中选择一行进行编辑后打开新状态.

我做错了什么?

Rad*_*ler 17

总是有效的是完整的状态定义:

// instead of this
// $state.go('.detail', {
// use this
$state.go('company.detail', {
    id: $scope.selectedItem.id //selectedItem and id is defined
});
Run Code Online (Sandbox Code Playgroud)

doc中定义了这些选项,但它们依赖于CURRENT状态:

to string
绝对状态名称或相对状态路径.一些例子:

  • $ state.go('contact.detail') - 将转到contact.detail状态
  • $ state.go('^') - 将转到父状态
  • $ state.go('^ .sibling') - 将进入兄弟姐妹州
  • $ state.go('.child.grandchild') - 将去孙子州