There are big datasets and I want to search some data in it. When I wrote some strings in textbox it will submit or $watch for every single letter I wrote in the input. How can I optimize it? Is there any directive or object for this in angularjs? I consider I can handle it with the setTimeout function. When user stops writing I can call $watch function. Is there any easy or right way to do it with angularjs?
1 Answer
You can use ng-model-options directive to adjust your model custom behavior. Use properties updateOn and debounce (delay). For instance:
ng-model-options="{
updateOn: 'default blur',
debounce: { 'default': 500, 'blur': 0 }
}"// 500ms delay for default event and no delay for 'blur' event
Here is the article about it in the official docs.
ng-model-options="{updateOn: 'blur'}"docs.angularjs.org/api/ng/directive/ngModelOptions