首页 > 解决方案 > rootScope 变量为 ng-if 延迟了两秒

问题描述

下面的代码是 app.js

var app = angular.module('inkwiry', [
    'ngSanitize',
    'ui.select',
    'ui.bootstrap',
    'ngCookies',
    'oc.lazyLoad',
    'ngAnimate',
    'ui.bootstrap-slider',
    'duScroll',
    'ui.router',
    'ngResource',
    'jQueryScrollbar',
    'angular-confirm',
    'ngCkeditor',
    'ngScrollbars',
    'angularUtils.directives.dirPagination',
    'ngDragDrop',
    'fixed.table.header',
    'stripe'
]);

app.run(function($rootScope, $state, $location, $window) {

    $rootScope.$on("$stateChangeStart", function(event, toState, toParams, fromState, fromParams) {
        $rootScope.loader = {
            loading: true
        };

        console.log('app start');
    });

    $rootScope.$on("$locationChangeSuccess", function(event, toState, toParams, fromState) {
        $rootScope.loader = {
            loading: false
        };

        console.log('app end');
    });
});

2) index.html

<div id="overlay" class="overlay" ng-if="loader.loading">
    <div class="loading" id="loading">
        <img src="external/img/ripple.svg">
        <h1>Loading, Please wait...</h1>
    </div>
</div>

我已经尝试了很多方法,但在本地它工作正常,但仍然存在同样的问题,但在服务器上它来晚了。变量的状态正在改变,但它会在 2 到 3 秒后应用于 div。我已经删除了 ngAnimate 也仍然是同样的问题。可以帮忙。

标签: angularjs

解决方案


推荐阅读