Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular debounce only for user input

I have a reactive form setup in Angular2. In a component i subscribe to value changes of a form control with debounce time of 500ms like:

myForm.get("myField").valueChanges.debounceTime(500).subscribe(...);

Is there a way to skip the debounce time if the value was changed by code, not by user? Or is there a way to split those 2 events?

like image 300
Matúš Zábojník Avatar asked May 22 '26 06:05

Matúš Zábojník


1 Answers

Where you set your value programatically, you can use emitEvent:false, where in the docs is stated...

If emitEvent is true, this change will cause a valueChanges event on the FormControl to be emitted. This defaults to true.

so setting this as false will not cause valueChanges to fire, so you can do the following if you are setting the value at some point:

this.myForm.get('myField').patchValue('my value', {emitEvent:false})
like image 177
AT82 Avatar answered May 24 '26 01:05

AT82



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!