我想知道是否有人在使用带有angular.js的ui路由器和/或如果未指定param时如何重定向,则需要使用状态参数的方法。我宁愿不必将控制器代码放在stateProvider配置中,但我愿意接受任何建议。
我接近了一些事情:
if (typeof $stateParams.myId == 'undefined') {
...
}
但是我不能把它解决,所以我不知道在哪里或如何检查。我有一个带孩子的抽象状态,抽象状态有状态参数....
.state('mystate', {
abstract: true,
url: '/state/:permalink',
template: '<div ui-view></div>'
})
.state('mystate.config', {
url: '/config',
templateUrl: 'partials/conf/config.html'
})
TIA
答案 0 :(得分:0)
行...
感谢levi ......我有部分工作:
.state('conference', {
abstract: true,
url: '/conference/:permalink',
data: {hasPerma: true},
module: 'conf',
template: '<div ui-view></div>',
})
.state('conference.config', {
url: '/config',
templateUrl: 'partials/conf/config.html'
})
...这允许我检查toState数据,但fromState模块(或数据)由于某种原因不显示:
.run(['$state', '$stateParams', '$rootScope', function($state, $stateParams, $rootScope) {
$rootScope.$on('$stateChangeStart', function(e, toState, toParams, fromState, fromParams) {
console.log(toState.data.hasPerma); //working
console.log('from: ' + fromState.module); //not showing up
})
}])
所以,如果我到了基本网址和/ conference / hello / config,我可以看到信息,但不是来自; - (