如何在FormBuilder控件的组中设置值



这是我在FormBuilder中的控件:

this.exampleForm.addControl("Date", this.formBuilder.group({
    'Month': [0],
    'Year': [0]
}));

我想更改控件中Month/Year的值,

我知道它有点像

let control = <FormControl>this.exampleForm.controls['Date'];
control.setValue(1);

但我相信它可以像一样完成

<FormArray>this.exampleForm.controls['Date'];
let control = <FormArray>this.exampleForm.controls['Date'];
control.controls['Month'].setValue("0"); // setting value here 

来源:https://angular.io/docs/ts/latest/api/forms/index/FormArray-class.html

最新更新