Reputation: 2103
I have a function which invokes whenever the model changed. I want to use debounced function inside the modelChange function.
I am using lodash
debounce but it is not invoking the function what am i doing wrong?
modelChange Function:
onModelChange(model) {
_.debounce(function() {
alert('debouned');
}, 2000)
}
Here is link to Stackbiltz
Upvotes: 1
Views: 512
Reputation: 3439
Creating method for debouncing
and calling it inside of onModelChange
should do the trick:
debouncedOnChange = _.debounce(function() {
alert('debounced');
}, 2000);
onModelChange(model) {
// alert('model has been changed');
this.debouncedOnChange();
}
Upvotes: 1