简体   繁体   English

需要帮助以延迟angularjs中的搜索结果

[英]Need help to delay of search results in angularjs

I want to write a code that gives the results after some delay of user search instead of instantaneous result. 我想编写一段代码,在用户搜索延迟一段时间后给出结果,而不是瞬时结果。 Can I do that using a filter? 我可以使用过滤器吗?

Angular 1.3 introduces debounce options in ng-model , which does exactly what you need - delay the changes in the models. Angular 1.3在ng-model引入了debounce选项,该功能完全可以满足您的需要-延迟模型的更改。

<div ng-controller="ExampleController">
  <form name="userForm">
    <label>Name:
      <input type="text" name="userName"
             ng-model="user.name"
             ng-model-options="{ debounce: 1000 }" />
    </label>
    <button ng-click="userForm.userName.$rollbackViewValue(); user.name=''">Clear</button>
    <br />
  </form>
  <pre>user.name = <span ng-bind="user.name"></span></pre>
</div>

https://docs.angularjs.org/api/ng/directive/ngModelOptions https://docs.angularjs.org/api/ng/directive/ngModelOptions

For further information, take a loot at discussion here How to put a delay on AngularJS instant search? 有关更多信息,请在此处进行讨论,以获取更多乐趣。 如何延迟AngularJS即时搜索?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM