How to display wait message in AngularJS while data loading?

后端 未结 5 729
余生分开走
余生分开走 2021-02-04 03:22

I\'m new in AngularJS and trying to find the way how to display wait message while data loading? I mean data starts loading, display message and remove it when data loading is d

5条回答
  •  梦如初夏
    2021-02-04 03:43

    Edit: does not work on version 1.3.0 . Use request/response interceptors.

    If you want to listen to all requests globally and display a loading widget whenever there's a request pending, you can count the requests using request/response transformers. You simply add a counter and increase on a new request and decrease it on response. I use a provider for that:

    $httpProvider
      .defaults
      .transformRequest
      .push(function(data) {
          requestNotificationProvider
          .fireRequestStarted(data);
          return data;
    });
    

    And the same for transformResponse. Then the same provider holds the information on how many requests are pending and you can use them in a directive. You can read (& copy/paste the code) a full blog post on that here: http://www.kvetis.com/2014/01/angularjs-loading-widget.html There's a working demo in attached.

提交回复
热议问题