javascript - 在 AngularJS 中添加进度圈的适当方法

标签 javascript html angularjs progress

我正在使用 AngularJS。我的 Controller 中有一个函数可以从服务器获取 .json 文件,处理数据并将其存储在 $scope 中。
所以基本上这个函数在页面加载时需要最多的时间。

所以我有这样的东西,我的页面已经加载但是我的表(用 ng-repeat 填充)没有。加载表需要几秒钟。在加载表格时,我想像这样添加进度圈:

enter image description here

在 AngularJS 中什么是合适的方法?

这是一个 Controller 演示:

 var serverData = $http.get('data/topCarObj.json');
 function sortCars(){
    angular.forEach($scope.tabArray, function(tab){
        serverData.success(function(data){
            angular.forEach(data, function(key){
                ....
                return myCarList;
            });
        });
     });
}

最佳答案

在 Controller 中:

$scope.getData = function() {    // wrap a data getting code in a function
        $scope.loading = true;     // define a variable that indicate the loading status   // true here
        $http.get('path_to_json').success(function (data) {   // get the data 
            $scope.loading = false;     // loading is finished so loading = false
        })
        .error(function (data, status) {
             $scope.loading = false;    // loading = false when there is a error
        });
}

$scope.getData();         // call the function to get data

在 View 中:

<img src="loading.gif" ng-show="loading" /> // show the loading.gif when `$scope.loading` variable is `true`

关于javascript - 在 AngularJS 中添加进度圈的适当方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26116281/

相关文章:

javascript - div值改变时执行javascript函数

javascript - Promises 和 Deferred : . did() 和 .then() 被调用,尽管 .resolve() 在 Deferred 对象上被调用

javascript - javascript 按钮不显示

angularjs - JSON 中的意外标记 u 位于位置 0

javascript - 我可以在 .on ('keyup' 上放置一个计时器来减少更新次数吗?

javascript - 向网站添加打印按钮(将自动设置缩放、边距和隐藏页眉/页脚以进行打印)

javascript - Meteor React - 发布/订阅不起作用

javascript - d3js : time scaling and "1901"

javascript - Jquery:TypeError: $(...)._TMS 不是函数

angularjs - 更改 $ionicHistory.backView() 的 stateParams 后返回