Nik*_*esh 23 angularjs angular-ui-router
这是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'
})
}
]);
Run Code Online (Sandbox Code Playgroud)
在我正在执行的登录控制器中
$state.go('useractivities', {});
Run Code Online (Sandbox Code Playgroud)
这给出了一个错误"无法解决'来自'''''的'useractivities'
我尝试了一些类似的东西
$location.url('useractivities')
Run Code Online (Sandbox Code Playgroud)
但没有运气,谁能告诉我哪里出错了?
Rad*_*ler 30
这里的问题是,to在PARAM的$state.go()电话必须是现有的国家名称.而'activities'不是现有的名字......这是'/activities'
我首先建议使用不同的状态命名:
$stateProvider
// instead of this
// .state('/',{
// let's use this state name
.state('login',{ // this is a STATE Name
url: "/",
controller: 'Login',
templateUrl: 'login.html'
})
// instead of this
// .state('/activities',{
// use this
.state('activities',{ // this is a STATE Name
url: "/activities",
controller: 'activitiesController',
templateUrl: 'useractivities.html'
})
Run Code Online (Sandbox Code Playgroud)
然后这将有效
$state.go('activities', {}); // we use STATE Name here
$state.go('login', {}); // also state name...
Run Code Online (Sandbox Code Playgroud)
点击此处了解更多详情:
to字符串绝对状态名称或相对状态路径
要转换到的状态的名称或相对状态路径.如果路径以^或开头.然后它是相对的,否则它是绝对的.
一些例子:
$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.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
47925 次 |
| 最近记录: |