enable/disable form control fires valueChanges Angular 2 Forms

Ben picture Ben · Mar 15, 2017 · Viewed 17.6k times · Source

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?

Answer

Ali Shahzad picture Ali Shahzad · Mar 15, 2017

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.