Delaying AngularJS route change until model loaded to prevent flicker

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

    Delaying showing the route is sure to lead to an asynchronous tangle... why not simply track the loading status of your main entity and use that in the view. For example in your controller you might use both the success and error callbacks on ngResource:

    $scope.httpStatus = 0; // in progress
    $scope.projects = $resource.query('/projects', function() {
        $scope.httpStatus = 200;
      }, function(response) {
        $scope.httpStatus = response.status;
      });
    

    Then in the view you could do whatever:

    Loading
    Real stuff
    ...
    Error, not found, etc. Could distinguish 4xx not found from 5xx server error even.

提交回复
热议问题