On my angular component, which implements ControlValueAccessor
, I'm having a problem with fields getting blanked. I'm doing this:
ngOnInit() {
this.formGroup.get('name')?.valueChanges.subscribe(x => {
this.formGroup.patchValue(version: null)
})
}
writeValue(...) {
this.formGroup.setValue({
name: ...,
version: ...
})
this.changeDetectorRef.markForCheck()
}
If they update the name, they have to pick a new version. My problem is that when writeValue
gets called, that triggers the valueChanges
operations, and so even though I gave a version, the version is always empty.
How do I work around that?
You can prevent
valueChanges
from being called by passing an additional object to yoursetValue
call as so:{ emitEvent: false }