我正在使用最新版本的Angular(v6.0.5)。
我有一个由3个通用控件组成的FormGroup,根据某些逻辑,我想将其他多个控件添加到同一FormGroup中。
我知道我可以使用,this.form.addControl()但我不想为每个单独的表单控件执行此操作
是否有捷径可寻?
例:
this.form = this.formBuilder.group({
'id': new FormControl('', Validators.required),
'firstName' new FormControl('', Validators.required),
'lastName' new FormControl('', Validators.required)
});
if (blah) {
// Append more FormControls here to same FormGroup
this.form.addControl('houseNumber', new FormControl(''));
this.form.addControl('street', new FormControl(''));
this.form.addControl('postCode', new FormControl(''));
}
Run Code Online (Sandbox Code Playgroud)