0
所以我有這部分應用程序結構,我想要實現的行爲是:我想在用戶嘗試訪問未經授權的路由時觸發一個事件,然後在LoginCtrl
上監聽該事件
//First controller in application
<body data-ng-controller="GatewayCtrl">
<div id="wrapper" data-ui-view="main"></div>
</body>
//then I have route which has `LoginCtrl` controller
$stateProvider
.state('login', {
url: '/login',
views: {
'main': {
templateUrl: 'login.html',
controller: 'LoginCtrl'
}
}
});
app.run(['$rootScope', function ($rootScope) {
$rootScope.$on('$stateChangeStart', function (event, next) {
$rootScope.$broadcast('test-event');
});
}]);
mdm.controller('LoginCtrl', ['$scope', function ($scope) {
$scope.$on('test-event', function() {
console.log('event');
});
}]);
mdm.controller('CounterCtrl', ['$scope', function ($scope) {
$scope.$on('test-event', function() {
console.log('event');
});
}]);
現在的問題是,事件被射擊GatewayCtrl
控制器,但沒有LoginCtrl
。
是什麼導致了這個問題,我該如何解決它?
你可以發佈'GatewayCtrl'代碼嗎?也許這是取消事件? – 2015-03-30 19:20:03