I think you are missing some thing here with formGroup
and formControlName
you should do:
myForm: FormGroup;
firstName = '';
lastName = '';
on ngOnInit
this.myForm = this.formBuilder.group({
firstName: [this.firstName],
lastName: [this.lastName]
});
this.myForm.controls['firstName'].valueChanges.subscribe(value => {
console.log(value);
});
and In HTML
<form [formGroup]="myForm">
...
<input name="firstName" [(ngModel)]="firstName" formControlName="firstName" placeholder="enter name"/>
<input name="lastName" [(ngModel)]="lastName" formControlName="lastName" placeholder="enter last name"/>
...
</form>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…