$ stateChangeStart在用户刷新浏览器时不起作用 [英] $stateChangeStart don't work when user refresh browser

查看:352
本文介绍了$ stateChangeStart在用户刷新浏览器时不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Please, I'm using ui-router on my project. $stateChangeStart event work fine when the user navigate between the states. But it doesn't work if I refresh the browser.

这是我的源代码:

(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 将触发。

A user refresh does not fire $stateChangeStart or $stateChangeSuccess. However $viewContentLoading and $viewContentLoaded does fire.

所以可以尝试以下操作:

So can you try the following:

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

这篇关于$ stateChangeStart在用户刷新浏览器时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆