angularjs – 角ui.router state.go(‘statename’)不工作
发布时间:2020-12-17 07:47:16 所属栏目:安全 来源:网络整理
导读:这是angular.ui.router的定义 app.config([ '$stateProvider','$urlRouterProvider',function($stateProvider,$urlRouterProvider){ $urlRouterProvider.otherwise('/'); $stateProvider.state('/login',{ url: "/",controller: 'Login',templateUrl: 'login
这是angular.ui.router的定义
app.config([ '$stateProvider','$urlRouterProvider',function($stateProvider,$urlRouterProvider){ $urlRouterProvider.otherwise('/'); $stateProvider.state('/login',{ url: "/",controller: 'Login',templateUrl: 'login.html' }) .state('/useractivities',{ url: "/activities",controller: 'activitiesController',templateUrl: 'useractivities.html' }) } ]); 在登录控制器中,我正在执行 $state.go('useractivities',{}); 这会导致错误“无法从状态’/’解析’useractivities’ 我已经尝试了几件事情 $location.url('useractivities') 但没有运气,任何人都可以告诉我出了什么问题?
这里的问题是,$state.go()调用的参数必须是现有的状态名称.而“活动”不是现有的名称,它是’/ activities’
我首先建议使用不同的状态命名: $stateProvider // instead of this // .state('/',{ // let's use this state name .state('login',{ // this is a STATE Name url: "/",templateUrl: 'login.html' }) // instead of this // .state('/activities',{ // use this .state('activities',{ // this is a STATE Name url: "/activities",templateUrl: 'useractivities.html' }) 然后这将工作 $state.go('activities',{}); // we use STATE Name here $state.go('login',{}); // also state name... 请查看这里了解更多详情: $state.go(to [,toParams] [,options])
$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 a grandchild state. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |