【发布时间】:2016-06-05 13:16:22
【问题描述】:
我正在为 ES6 和 webpack 使用 Bable。我正在使用 angular 1.x.x 并构建一个应用程序。直到现在我没有遇到任何问题。我想要一个可以跟踪所有路由更改的功能。我正在使用 UI 路由器。问题是$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);
请让我知道我做错了什么,因为状态正在改变,但$stateChangeStart 事件永远不会被触发。 run 方法是我连接$stateChangeStart 监听器的地方。
我猜它与 ES6 有关,但我找不到任何参考。 谢谢。
【问题讨论】:
-
试试 $rootScope.$on('$locationChangeStart', ...)
-
您为什么不将所有这些内容剥离到minimal reproducible example 并与我们分享?
-
@FranePoljak Dude 我正在使用 UI-Router,所以请在将其标记为负面之前通读一遍!
-
@iH8 你可以看看代码中的run方法。抱歉包含这么多。我会编辑它。
-
投反对票的不是我 :)
标签: javascript angularjs angular-ui-router ecmascript-6 webpack