我怎么每n秒后触发angularjs服务用户键入的东西 [英] how do I trigger an angularjs service after every nth seconds a user typed something
问题描述
我的用户类型的东西。我想保存类型的数据后,每1000毫秒说用户停止输入。
My user types something. I want to save the typed data after every say 1000ms the user stopped typing.
我不想用1000毫秒$ INTERVALL使用。
I do NOT want to use $intervall with 1000ms.
我怎样才能做到这一点使用最新的1.3.11角?
How can I do this using latest angular 1.3.11 ?
推荐答案
采用了棱角分明1.3
Using Angular 1.3
<input ng-model='data' ng-model-options="{ debounce: 1000 }" />
在角文档
在你的控制器,你可以看$(数据),并随时更改数据保存更改(就像你,如果你没有去抖动输入)。
In your controller, you can $watch('data') and save your changes whenever data is changed (just like you would if you weren't debouncing the input).
您还可以使用NG-变化,而不是$手表,但是我没有测试如何与反跳交互(但基于其他答案,看起来像预期会工作)。
You may also be able to use ng-change instead of $watch, but I haven't tested how that interacts with debounce (but based on other answers, looks like it would work as expected).
这篇关于我怎么每n秒后触发angularjs服务用户键入的东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!