Mic*_*ael 3 html javascript progress angularjs
我正在使用AngularJS.我的控制器中有一个函数,它.json从服务器获取文件,处理数据并将其存储$scope.
所以基本上这个功能在页面加载时需要最大的时间.
所以我有这样的东西,我的页面已经加载但是我的桌子(填充ng-repeat)却没有.加载表需要几秒钟.当表正在加载时,我想添加进度循环:

什么是在AngularJS中做到这一点的适当方法?
这是一个控制器演示:
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;
});
});
});
}
Run Code Online (Sandbox Code Playgroud)
在控制器中:
$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
Run Code Online (Sandbox Code Playgroud)
在视图中:
<img src="loading.gif" ng-show="loading" /> // show the loading.gif when `$scope.loading` variable is `true`
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6447 次 |
| 最近记录: |