我使用 this创建我的网站,当我创建一个带有 $rootScope.on('$stateChangeStart') 的运行方法时,它不起作用。这是代码:
.run('Url',function($rootScope, $state, $location){
'ngInject' ;
console.log('Is working');
function message(to, toP, from, fromP) {
return from.name + angular.toJson(fromP) + " -> " + to.name + angular.toJson(toP);
}
$rootScope.$on("$stateChangeStart", function(evt, to, toP, from, fromP) {
console.log("Start: " + message(to, toP, from, fromP));
console.log('Not working');
});
当我加载网站时,第一个日志正常运行,但第二个日志不正常,知道问题出在哪里吗?
最佳答案
如果您更改版本。
对于新的 ui-router(Angular 1.x 版本)。您需要加载 stateEvents 文件。
<script src="lib/angular-ui-router/release/stateEvents.min.js"></script>
在您的应用程序中添加加载它
angular.module('MyApp', ['ui.router', 'ui.router.state.events', ...
关于angularjs - Angular $rootScope.on ('$stateChangeStart' ) 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41779202/