angularjs - Angular $rootScope.on ('$stateChangeStart' ) 不工作

标签 angularjs debugging angular-ui-router

我使用 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/

相关文章:

javascript - 不同的 ng-switch 动画

flutter - 为 x86 构建的 Android SDK 不支持配置文件模式?

javascript - 无法存储使用 Angular.js UI Router 构建的多步骤表单的数据

javascript - 捕获正在执行的 javascript 代码的工具

java - eclipse 中的 SSL 调试

angularjs - Angular ui路由器的默认路由

javascript - Controller 不应在 $location.path() 上重新加载

javascript - 将服务注入(inject)指令返回未定义

javascript - 当textarea绑定(bind)到模型时angularjs中的默认textarea值

java - 条形码生成服务器端还是客户端?