I have two angular components a parent and a child, both with their own form fields. I setup change listeners in both components to listen to the form control value changes and disable some fields upon typing in some form controls.
When attempting to disable a form control inside component-2 from the change listener in component-1, the form control is not disabled right away instead it disables after typing the second character.
After some research I discovered that using the distinctUntilChanged() in my change listener subscription was the cause. removing the distinctUntilChanged() from the subscription resolved the primary issue, however, now it is causing the following console error: ERORR: RangeError: Maximum call stack size exceeded.
changeListener(){
this.myForm.get('sample_control_name').valueChanges.subscribe(v => {
if(isNotEmpty(v)) {
this.childComponent.getFormGroup().get('sample_control_name_1').disable();
}
else {
this.childComponent.getFormGroup().get('sample_control_name_1').enable();
}
})
}