Track to see when a view changes in angularjs

Take a look at this thread it looks like the $httpProvider.responseInterceptors are a good place to add this type of thing.

This fiddle shows a good example on where to add code to start/stop a spinner for ajax requests. This fiddle is similar but actually shows and hides a ‘Loading…’ div.

If you only want to show a spinner when views change you can limit your start/stop code to when content-type equals text/html similar to what this post shows with application/json.

Note: in my tests it looks like the headersGetter()['Content-Type'] in the spinnerFunction is omitted when retrieving my .html files whereas it is populated when making service calls.

Leave a Comment