【发布时间】:2019-07-23 09:43:59
【问题描述】:
我有带有表单的 Angular 6 应用程序。这是一个例子
export class ExampleComponent implements OnInit {
form: FormGroup;
constructor(private fb: FormBuilder) { }
ngOnInit() {
this.form = new FormGroup({
first: new FormControl(),
last: new FormControl()
});
this.markControlsAsDirty(this.form);
}
markControlsAsDirty(form: FormGroup) {
this.form.get('first').markAsDirty();
this.form.get('last').markAsDirty();
}
}
我不想获得单个控件并标记每个字段。 我可以将表单组中的所有控件都标记为脏吗?
更新我已被添加 stackblitz example 以表明之前的两个答案是错误的
【问题讨论】:
标签: angular typescript angular-reactive-forms