Since ngModel is updating instantly how to put a delay.
Lots of solutions using setTimeout()
, but this will cause the function to be called each time the model changes, a simple way to prevent this is to clear the timeout first
e.g.
timeOut;
timeOutDuration = 1000;
update_fields(data) {
clearTimeout(this.timeOut);
this.timeOut = setTimeout(() => {
//do something
}, this.timeOutDuration);
}
this will only call the function once after the last update is made and the timeOutDuration
has elapsed