Delaying AngularJS route change until model loaded to prevent flicker

后端 未结 13 2297
误落风尘
误落风尘 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:29

    I like darkporter's idea because it will be easy for a dev team new to AngularJS to understand and worked straight away.

    I created this adaptation which uses 2 divs, one for loader bar and another for actual content displayed after data is loaded. Error handling would be done elsewhere.

    Add a 'ready' flag to $scope:

    $http({method: 'GET', url: '...'}).
        success(function(data, status, headers, config) {
            $scope.dataForView = data;      
            $scope.ready = true;  // <-- set true after loaded
        })
    });
    

    In html view:

    See also: Boostrap progress bar docs

提交回复
热议问题