跟踪以查看 angularjs 中的视图何时更改 [英] Track to see when a view changes in angularjs

查看:24
本文介绍了跟踪以查看 angularjs 中的视图何时更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何在视图改变时使 angular fire 成为一个事件?或者就在请求和下载视图时?我正在尝试添加页面更改时的加载动画.

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.

这个小提琴 展示了一个很好的例子,说明在哪里添加代码来启动/停止 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.

如果您只想在视图更改时显示微调器,您可以将开始/停止代码限制为 content-type 等于 text/html 类似于 这篇文章 显示了 application/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.

注意:在我的测试中,spinnerFunction 中的 headersGetter()['Content-Type'] 在检索我的 .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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆