如何展示"正在进行中"在angularjs中,如果加载数据需要时间

时间:2015-09-18 06:38:54

标签: ajax angularjs performance browser angularjs-ng-repeat

当我的浏览器处于挂起状态时,我的ng-repeat需要很长时间才能加载。那么如何向用户展示加载正在进行中还是在angularjs中进行某种动画?

2 个答案:

答案 0 :(得分:1)

使用$ timeout或$ scope。$ evalAsync在ng-repeat渲染元素时显示加载器的意思,或者你也可以使用指令

HTML

<ul>
  <li ng-repeat='item in items' check-render>{{item}}</li>
<ul>
<div id='loader'></div>

Angularjs

app.directive('checkRender', function($timeout) {
    return {
        restrict: 'A',
        link: function(scope, el, attrs) {
            if (scope.$last === true) {
                $timeout(function() {
                    angular.element("#loader").fadeOut();
                });
            }
        }
    };
}); 

答案 1 :(得分:0)

有一些被称为ngProgress的东西就像一个You-Tube样式的进度条,它加载在页面的顶部边缘。您可以查看here

这也支持使用容器中的进度条。也许你可能喜欢这个。我不确定你将如何使用它,但是显示div的进度,我认为你的ng-repeat元素看起来会很好。