Assuming the template has code snippet like this:
<form #myForm="ngForm">
<md-input-container>
<input mdInput name="address" [formControl]="addressCtrl" [(ngModel)]="address" required>
</md-input-container>
</form>
And the component has something like this:
export class AddressComponent {
@ViewChild("myForm")
myForm: NgForm;
addressCtrl = new FormControl();
address: string;
constructor() {}
validate() {
this.addressCtrl.markAsTouched();
console.log("Is address valid? " + this.addressCtrl.valid);
console.log("Is myForm valid? " + this.myForm.form.valid);
}
}
The validate() is invoked by some other action, which aim at triggering the form validation programmatically.
However, in the console log, it shows that the addressCtrl is invalid while myForm is still valid.
Anyone knows how to update myForm status to be invalid if any of its child control is invalid?
Thanks!