AngularJS: show loading HTML until data is loaded

后端 未结 4 884
Happy的楠姐
Happy的楠姐 2020-12-23 14:35

How do I have AngularJS show a loading spinner until the data has finished loading?

If my controller has $scope.items = [{name: \"One\"}] set up statica

4条回答
  •  佛祖请我去吃肉
    2020-12-23 15:40

    @lucuma,

    Great answer, an alternative can be to inject $timeout and replace the native timeout function:

    var app = angular.module('plunker', []);
    
    app.controller('MainCtrl', function($scope, $timeout) {
    
            $scope.name = 'World';
            $scope.items = [{name: "One"}];
            $timeout(function() {
                    $scope.$apply(function() {
                            $scope.items[0].lateLoader = 'i just loaded';  
                    });
            }, 1000);
    });
    

提交回复
热议问题