What is the equivalent of jQuery ajax beforeSend in Angularjs?

前端 未结 2 1423
遥遥无期
遥遥无期 2020-12-14 03:46

I am familiar with Jquery AJAX call, which has different callbacks like beforeSend, success, complete, etc.

This is the example AJAX call with Jquery:



        
2条回答
  •  無奈伤痛
    2020-12-14 04:10

    You can use interceptors. Search for the word interceptor into the Angular $http documentation

    As the documentation says : For purposes of global error handling, >authentication, or any kind of synchronous or asynchronous pre-processing of >request or postprocessing of responses

    Here is a good Fiddle Example displaying a loading gif before the ajax call is sent.

    EDIT

    As Satpal commented, $httpProvider.responseInterceptors used in the Fiddle is deprecated. You should use $httpProvider.interceptors instead.

提交回复
热议问题