Delaying AngularJS route change until model loaded to prevent flicker

后端 未结 13 2322
误落风尘
误落风尘 2020-11-22 02:28

I am wondering if there is a way (similar to Gmail) for AngularJS to delay showing a new route until after each model and its data has been fetched using it

13条回答
  •  灰色年华
    2020-11-22 03:16

    This commit, which is part of version 1.1.5 and above, exposes the $promise object of $resource. Versions of ngResource including this commit allow resolving resources like this:

    $routeProvider

    resolve: {
        data: function(Resource) {
            return Resource.get().$promise;
        }
    }
    

    controller

    app.controller('ResourceCtrl', ['$scope', 'data', function($scope, data) {
    
        $scope.data = data;
    
    }]);
    

提交回复
热议问题