gpt4 book ai didi

javascript - $stateChangeStart 在 UI-Router ES6 中的状态变化时没有被触发?

转载 作者:数据小太阳 更新时间:2023-10-29 04:24:39 25 4
gpt4 key购买 nike

我正在为 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 有关,但我找不到任何引用资料。谢谢。

最佳答案

我遇到了类似的问题,最终意识到 stateChange* 事件在 ui-router 1.0 中已被默认弃用和禁用。我正在使用 1.0.0-alpha0。这些事件提供的功能现在可以使用转换 Hook 来实现。这在 1.0 alpha 版的发行说明中有所介绍,可在此处阅读:https://github.com/angular-ui/ui-router/releases/tag/1.0.0alpha0

关于javascript - $stateChangeStart 在 UI-Router ES6 中的状态变化时没有被触发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35581995/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com