简体   繁体   中英

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.

<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

For further information, take a loot at discussion here How to put a delay on AngularJS instant search?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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