Any ideas why when running the following code I get the valueChanges
event of 'firstName'
control fired?
let form: FormGroup = this.createForm(); form.controls['firstName'].enable(); form.controls['firstName'].valueChanges(value=>{ //some code });
As no value has changed (just the status), I wouldn't expect valueChanges
to be triggered here, only the statusChanged
.
Am I missing something?
If you set disabled to true when you set up this control in your component class, the disabled attribute will actually be set in the DOM for you. We recommend using this approach to avoid 'changed after checked' errors. Example: form = new FormGroup({ first: new FormControl({value: 'Nancy', disabled: true}, Validators.
No idea why it behaves as it does, but you can send emitEvent: false
to enable/disable without firing valueChanges
.
form.controls['firstName'].enable({ emitEvent: false });
Basically complete form is mapped on a model, so whenever you enable/disable any control, the form model's property changes. And because the model is changing so valueChanges
event will be triggered. I think its normal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With