admin管理员组文章数量:1356438
I am using AngularJS. I have a function in my controller that gets .json
file from the server, working with data and store it in $scope
.
So basically this function needs biggest amount of time when the page is loading.
So I have something like this, my page has loaded but but my table (that populates with ng-repeat
) has not. It takes few seconds to load the table. And while the table is loading I want to add progress circle like that:
What is appropriate way to do it in AngularJS?
Here is a controller demo:
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;
});
});
});
}
I am using AngularJS. I have a function in my controller that gets .json
file from the server, working with data and store it in $scope
.
So basically this function needs biggest amount of time when the page is loading.
So I have something like this, my page has loaded but but my table (that populates with ng-repeat
) has not. It takes few seconds to load the table. And while the table is loading I want to add progress circle like that:
What is appropriate way to do it in AngularJS?
Here is a controller demo:
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;
});
});
});
}
Share
Improve this question
edited Sep 30, 2014 at 8:42
Michael
asked Sep 30, 2014 at 8:35
MichaelMichael
16.2k39 gold badges98 silver badges145 bronze badges
1
- Where is actual request code? – dfsq Commented Sep 30, 2014 at 8:38
2 Answers
Reset to default 6In 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
In View:
<img src="loading.gif" ng-show="loading" /> // show the loading.gif when `$scope.loading` variable is `true`
In your controller set $scope.doneLoading = true
after all data is received and processed.
In your view have the animated image show with ng-if='!doneLoading'
and hide other ponents with a similar, negated condition.
Alternatively you could also have a global throbber that is controlled by a watch on $http.pendingRequests
- but unfortunately the docs say about pendingRequests that "This is primarily meant to be used for debugging purposes."
Also from a usability view I would prefer showing a throbber only at those parts of the view that are actually currently loading.
本文标签: javascriptAppropriate way to add progress circle in AngularJSStack Overflow
版权声明:本文标题:javascript - Appropriate way to add progress circle in AngularJS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744029588a2578661.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论