How can I listen to valueChanges and setValue of a AbstractControl in reactive forms

Viewed 9687

I am new to Angular and I have a Reactive Forms with AbstractControl that subscribe for valueChange to listen for any values change in input field. Inside the subscribed function I want to change the value of the input under a certain condition.

this.abstractControl.valueChanges.subscribe(data => {
...
   if(.....) {
       this.formGroup.patchValue({
           name: result
       )}
    }
...
}

I tried to use this.abstractControl.setValue(result) does'nt work too.

I get an error in setting the value.

ERROR RangeError: Maximum call stack size exceeded

What is the recommended way of listening to a value change and changing the value accord to a condtion?

1 Answers
Related