如何去$ state.go() [英] How to $state.go()

查看:61
本文介绍了如何去$ state.go()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是我的$ 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
});

解决方案

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
});

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') - will go to the contact.detail state
  • $state.go('^') - will go to a parent state
  • $state.go('^.sibling') - will go to a sibling state
  • $state.go('.child.grandchild') - will go to grandchild state

这篇关于如何去$ state.go()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆