Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 ControlGroup valueChanges on initial bind

I have a form with some <input type="text"> widgets and I have noticed that ControlGroup.valueChanges is being called upon initial databind when using [ngFormModel] and ngControl.

This means that the user thinks that the form has been changed upon initial load.

Is this normal or should I be using a different observable to track changes made the by the user?

I am using Angular2 RC3 and the following version import for forms:

import {ControlGroup, Validators, FormBuilder} from '@angular/common';
like image 618
geejay Avatar asked Jul 10 '16 23:07

geejay


1 Answers

I think that's just how it works, however if you just want to track if changes are made by user, you should employ ControlGroup.dirty or formControl.dirty with the changes Observable.

ControlGroup.valueChanges.subscribe(() => {

 if(ControlGroup.dirty){
   console.log('This change is made by User.');
 } 
 else {
   console.log('This change is Automated. before any User interaction.');
 }

})
like image 111
Ankit Singh Avatar answered Sep 21 '22 09:09

Ankit Singh