我在angular-login-example学习,它通过$ stateChangeStart测试身份验证
下面是我的测试代码
的index.html:
<div ng-include="'test.html'"></div>
<div ui-view></div>
的test.html
<div ng-controller="TestCtrl"></div>
app.js
.config(function ($urlRouterProvider) {
$urlRouterProvider.otherwise('/topics');
})
.config(function ($stateProvider) {
$stateProvider
.state('topics', {
url: '/topics',
template: '11111111'
});
}),
.controller('TestCtrl', function ($rootScope) {
$rootScope.$on('$stateChangeStart', function (event, to, toParams, from, fromParams) {
console.log('xxxxxx');
});
})
如果我访问http://localhost/,它会重定向到http://localhost/#/topics,并输出&#39; xxxxxx&#39;,但如果我访问http://localhost/#/topics,则不输出任何内容!
如果我不使用ng-include,那就说:
的index.html
<div ng-controller="TestCtrl"></div>
我访问http://localhost/或http://localhost/#/topics,始终输出&#39; xxxxxx&#39;?
是ui-router的错误吗?