gpt4 book ai didi

angularjs - 用户刷新浏览器时 $stateChangeStart 不起作用

转载 作者:行者123 更新时间:2023-12-02 03:17:35 26 4
gpt4 key购买 nike

请,
我在我的项目中使用 ui-router。 $stateChangeStart当用户在状态之间导航时,事件工作正常。
但是如果我刷新浏览器,它就不起作用。

这是我的源代码:

(function(){
'use strict';

angular.module('app.overlay')
.directive('ibLoading', ['$rootScope' , '$timeout', loading]);

function loading($rootScope , $timeout){
console.log("In dirrective");
var directive = {
restrict:'EAC',
link:link
};

function link(scope, element) {

$rootScope.$on('$stateChangeStart', function() {
$timeout(function(){
element.addClass('show');
} , 50);
});

$rootScope.$on('$stateChangeSuccess', function() {
$timeout(function(){
element.removeClass('show');
} , 700);
});

}

return directive;
}
})();

我的布局文件
<div ng-controller="ShellController as vm">
<header class="clearfix">
<ht-top-nav navline="vm.navline"></ht-top-nav>
</header>
<section id="content" class="content">
<!--<div ng-include="'app/layout/sidebar.html'"></div>-->
<div ui-view></div>
<div class="ib-loading">Loading ...</div>
</section>
</div>

最佳答案

用户刷新不会触发 $stateChangeStart 或 $stateChangeSuccess。然而 $viewContentLoading $viewContentLoaded 会火。

那么您可以尝试以下操作:

         $rootScope.$on('$viewContentLoading', function() {
$timeout(function(){
element.addClass('show');
} , 50);
});
$rootScope.$on('$viewContentLoaded', function() {
$timeout(function(){
element.removeClass('show');
} , 700);
});

关于angularjs - 用户刷新浏览器时 $stateChangeStart 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35658296/

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