跟踪时看到在angularjs一个视图改变 [英] 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.
推荐答案
看看这个线程它看起来像 $ httpProvider.responseInterceptors
是一个很好的地方加入这种类型的东西。
Take a look at this thread it looks like the $httpProvider.responseInterceptors
are a good place to add this type of thing.
这拨弄显示了在哪里添加code,开始一个很好的例子/停止Ajax请求好手。 这小提琴是类似的,但实际显示和隐藏了一个正在载入DIV。
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.
如果您只想显示一个微调时的观点改变你可以限制你的启动/停止code时内容类型
等于 text / html的
类似这个帖子显示了<$ C什么$ C>应用程序/ JSON 。
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
.
请注意:在我的测试中,它看起来像 headersGetter()['内容类型']
在 spinnerFunction
检索我的.html文件时它而做服务呼叫时,填充省略。
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.
这篇关于跟踪时看到在angularjs一个视图改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!