如何 $state.go() [英] How to $state.go()
问题描述
是我的 $stateProvider:
Is my $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),但此代码不起作用(从公司"状态调用):
It's work for 'company' state (I use ui-sref), but this code not work (called from 'company' state):
$state.go('.detail', {
id: $scope.selectedItem.id //selectedItem and id is defined
});
我从 StackOverflow 阅读了官方文档和答案,但没有找到解决方案.我不能使用ui-sref,我使用ui-grid,并且在从表中选择一行进行编辑后打开了新状态.
I read official docs and answers from StackOverflow, but I don't found solution. I can't use ui-sref, I use ui-grid, and new state opened after select one row from table for editing.
我做错了什么?
推荐答案
始终有效的是完整的状态定义:
What would always work is the full state definition:
// instead of this
// $state.go('.detail', {
// use this
$state.go('company.detail', {
id: $scope.selectedItem.id //selectedItem and id is defined
});
在 doc 定义了这些选项,但它们取决于当前状态:
In doc there are defined these options, but they depend on CURRENT state:
到 字符串
绝对状态名称或相对状态路径.一些例子:
to string
Absolute state name or relative state path. Some examples:
- $state.go('contact.detail') - 将转到 contact.detail 状态
- $state.go('^') - 将转到父状态
- $state.go('^.sibling') - 将进入兄弟状态
- $state.go('.child.grandchild') - 将转到孙子状态
这篇关于如何 $state.go()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!