Angular - show加载图标取决于$ http.pendingRequests

时间:2016-12-14 07:10:42

标签: javascript angularjs laravel angular-ui-router

我正在加载图标,理想情况下,只要 $ http.pendingRequests 不等于零,并且旧状态不等于新状态,我就能显示它(我使用< em> Angular Ui-Router )。这是我的代码:

master.blade.php:

.
.
.
<div class="loading-burger-holder" data-loading>
    <div class="burger-overlay"></div>
    <div class="burger-loader">
        <img src="/app/user/assets/img/img-ico/loader.gif" class="img-responsive">
        <p>plaese wait ...</p>
    </div>
</div>
.
.
.

clientGateway.js:

.
.
.

$rootScope.isLoading = function () {
    console.log($http.pendingRequests.length  ,"length");
    return $http.pendingRequests.length > 0;
};

var state = '-';
$rootScope.$watch($rootScope.isLoading, function (v) {
    if (v && state != $state.current.name) {
        $('.loading-burger-holder').show();
    } else {
        state = $state.current.name;

        $('.loading-burger-holder').hide();
    }
});
.
.
.

它并不适用于所有情况。是否会非常感谢任何替代解决方案?

1 个答案:

答案 0 :(得分:0)

你不需要使用手表

<div ng-show="!isLoading()" class="burger-overlay"></div>
<div ng-show="isLoading()" class="burger-loader">
    <img src="/app/user/assets/img/img-ico/loader.gif" class="img-responsive">
    <p>plaese wait ...</p>
</div>