1

I want to show a loading message while sending http request and hide loading on request complete, and i want to use this for all the http request. Is there any global function in angular to do this..

user3189828
  • 185
  • 1
  • 4
  • 16
  • 4
    Possible duplicate of [Showing Spinner GIF during $http request in angular](http://stackoverflow.com/questions/15033195/showing-spinner-gif-during-http-request-in-angular) – Dandy Jan 15 '16 at 09:08

2 Answers2

0

A JavaScript HTTP request will not block and you will provide a callback which is called when the request is complete. This means that you could do this (pseudocode, since you didn't provide example code):

function callback(httpResponse) {
  hideLoadingMessage();
  dostuffWithResponse(httpResponse);
}
// callback is callled when HTTP request is complete
doHttpRequest(params, callback);
// the code after continues to execute despite the HTTP request not being ready
showLoadingMessage();

So the code execution continues after the HTTP request is sent. The callback will be called when the HTTP request is complete. In practice you need to also handle errors.

user2170710
  • 140
  • 1
  • 1
  • 6
  • This answer isn't really appropriate for an angularjs application where you would use a service returning a promise rather than a callback and instead of functions to show or hide a message you simply manipulate the data model appropriately. See the 'possible duplicate' suggestion for more appropriate answers. Specifically http://stackoverflow.com/a/15033322/107660 – Duncan Jan 15 '16 at 09:20
0

Quick Google search returned a fair amount of results for Angular:

Loading spinner you can implement onClick.

http://ngmodules.org/modules/angular-loading-spinner

Previously asked question with similar circumstances:

Showing Spinner GIF during $http request in angular

And finally, codepen.io examples (might be broken now though)

http://codetunnel.io/how-to-do-loading-spinners-the-angular-way/

I would highly recommend trying before asking in future. We need code examples of what you've tried or where you are at right now. This isn't a simple piece of code unless you're using a plugin (which you could have found yourself).

I'd recommend in future, try providing some context and examples.

Community
  • 1
  • 1
Dandy
  • 1,466
  • 16
  • 31