Vin*_*oft 3 forms angular formgroups
我正在Angular6中编写一个系统.系统使用表格,用FormGroup.实现.
问题:如何在初始化后扩展表单?
例:
ngOnInit() {
this.form = new FormGroup({
'field_1': new FormControl(null),
'field_2': new FormControl(null)});
if (a == 'some value') {
// Extend this.form with field_2 and field_3
}
}
Run Code Online (Sandbox Code Playgroud)
小智 8
有一种方法叫做addControl:https:
//angular.io/api/forms/FormGroup#addControl
this.form.addControl('field3', new FormControl(null));
| 归档时间: |
|
| 查看次数: |
566 次 |
| 最近记录: |