How to show loading message while sending angularj http request

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..

Answers


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.


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.


Need Your Help

python 3 in emacs

python emacs python-3.x emacs23

I changed two days ago to Emacs 23, which lately gave me a lot of headache, especially, as I have two Python versions installed, the older 2.7 and 3. As I generally want to start the python 3 inter...

CodeIgniter POST works in localhost but not on live server

php mysql forms codeigniter login

I'm using CodeIgniter & GoCart and all of a sudden found out that the login and register functions which work perfectly in my localhost environment are not working on the live server.