0

I am using below library to use autocomplete directive in my module for AngularJS!. [https://github.com/JustGoscha/allmighty-autocomplete]

I want to execute a function when user has stopped typing, is there a way I can do this?

Mistalis
  • 17,793
  • 13
  • 73
  • 97
Raaj Dubey
  • 172
  • 1
  • 14
  • 1
    I'd imagine you could use [ng-model-options](https://docs.angularjs.org/api/ng/directive/ngModelOptions) specifically the `debounce` property. Dunno if it will work with that directive, but you can give it a try. – George Mar 27 '17 at 14:23
  • Use setTimeout() , and recreate it on every click. – KoIIIeY Mar 27 '17 at 14:29
  • 1
    According to the allmighty-autocomplete docs, there is an `on-type` attribute? Have you tried it? – DGarvanski Mar 27 '17 at 14:30
  • ya i have used on-type property but i want to execute my fuction once typing has been stopped – Raaj Dubey Mar 27 '17 at 14:31
  • You can possibly set a timeout in the function you are executing on the `on-type` event. It will get restarted every time the user types but won't if they stop typing. – DGarvanski Mar 27 '17 at 14:37

1 Answers1

4

You can do it using ng-change and ng-model-options (Angular 1.3+ only):

<input type="text"
       ng-model="myVar"
       ng-model-options="{debounce: 1000}"
       ng-change="functionToBeCalled()"/>
Mistalis
  • 17,793
  • 13
  • 73
  • 97
  • @RajDubey "*This doesn't work*" does not mean anything. What is the behavior? Do you have any error? What is your Angular version? – Mistalis Mar 27 '17 at 14:34
  • actually by using this what i do is just delay the response. but what I want is when user is typing there should be a loader and it stops typing options are shown – Raaj Dubey Mar 27 '17 at 14:46