当我将console.log
移动到rootscope.on上方时,它会打印出来,但由于某种原因,就好像根本没有达到rootscope.on一样:
'use strict';
var app = angular.module('myApp', ["ui.router"]);
app.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/login');
$stateProvider
.state('app', {
template: "<ui-view></ui-view>",
abstract: true
})
.state('app.login', {
url: '/login',
controller: 'loginCtrl',
templateUrl: 'content/auth/login.html',
requireLogin: false,
authorized: true
})
.state('app.register', {
url: '/register',
controller: 'registerCtrl',
templateUrl: 'content/auth/register.html',
requireLogin: true,
authorized: true
});
});
app.run(function($rootScope, $state) {
$rootScope.$('$stateChangeStart', function(event, toState) {
console.log("redirecting");
})
});
答案 0 :(得分:0)
您实际上并未拨打$on
。
更改
$rootScope.$('$stateChangeStart', function(event, toState) {
console.log("redirecting");
})
到
$rootScope.$on('$stateChangeStart', function(event, toState) {
console.log("redirecting");
})