在UI-Router ES6中状态更改时,$ stateChangeStart没有被触发?

Shi*_*esh 7 javascript angularjs ecmascript-6 angular-ui-router webpack

我正在使用Bable for ES6和webpack.我在角1.xx并建立一个应用程序.直到现在我没有遇到任何问题.我希望有一个功能,我可以跟踪所有的路线变化.我正在使用UI-Router.问题是$stateChangeStart无论如何都没有被触发.代码如下所述.

/*All includes are taken care of. Please look at the run method*/

angular.module('chpApp', [
        uirouter,
        angular_animate,
        uibootstrap,
        formly,
        formlyBootstrap,
        ngMessages,
        angularLoadingBar,
        'ngNotificationsBar',
        'jkuri.datepicker',
        'LocalStorageModule',
        'ncy-angular-breadcrumb',
        'mgo-angular-wizard',
        'luegg.directives',
        'ngToast',
        'ui.mask',
        /*Application Modules*/
        angularnvd3,
        chpConstants,
        menu,
        header,
        breadcrumb,
        auth,
        dashboard,
        programs,
        device
    ])
    .run(['$rootScope', function($rootScope) {
        $rootScope.$on('$stateChangeStart', () => {
            console.log('lol')
        })
    }])
    .config(routing);
Run Code Online (Sandbox Code Playgroud)

请让我知道我做错了什么,因为状态正在改变,但$stateChangeStart事件永远不会被触发.该run方法是我与$stateChangeStart听众联系的地方.

我猜它与ES6有关,我无法找到任何参考.谢谢.

Eoi*_*oin 13

我遇到了类似的问题,并最终意识到stateChange*默认情况下ui-router1.0 中的事件已被弃用和禁用.我正在使用1.0.0-alpha0.现在可以使用转换挂钩实现这些事件提供的功能.这可以在1.0 alpha的发行说明中介绍,可以在这里阅读:https://github.com/angular-ui/ui-router/releases/tag/1.0.0alpha0

  • @Eoin谢谢你,有同样的问题和[文档](https://github.com/angular-ui/ui-router/wiki#state-change-events)没有提到任何东西.我现在在文档中添加了一行,以便为人们节省一些时间 (2认同)

Bre*_*gan 8

扩展Eoins的答案,您可以在组件控制器中使用$ transitions上的钩子,如下所示

        $transitions.onStart({}, ()=>{
            $log.log('In start')
        });
        $transitions.onFinish({}, ()=>{
            $log.log('In finish')
        });
Run Code Online (Sandbox Code Playgroud)

https://github.com/angular-ui/ui-router/releases/tag/1.0.0alpha0