Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
312 views
in Technique[技术] by (71.8m points)

Track to see when a view changes in angularjs

Does anyone know how to make angular fire an event when the view has changed? Or right when a view is requested and downloaded? I'm trying to add loading animations for when pages change.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...