这是我的主要代码:
get emailFormArray() {
return this.formGroup.get("emails") as FormArray;
}
public ngOnInit() {
this.formGroup = this.formBuilder.group({
emails: this.formBuilder.array([]),
});
this.addEmailFormGroup();
}
public addEmailFormGroup() {
this.emailFormArray.controls.push(
this.formBuilder.group({
email: ['', Validators.email],
}),
);
}
在我的模板中
{{ formGroup.valid }}
{{ emailFormArray.valid }}
<ng-container *ngFor="let email of emailFormArray.controls">
{{ email.valid }}
{{ email.get('email').valid }}
</ng-container>
当我输入一个无效的电子邮件时,模板中的结果是true true false false
,为什么formGroup
和emailFormArray
是有效的?谢谢!