相关疑难解决方法(0)

Reactive Forms: How to add new FormGroup or FormArray into an existing FormGroup at a later point in time in Angular 7

In the other examples at StackOverflow there are many questions about using FormGroups in FormArrays. But my question is the opposite.

FormArrays have a push method, that makes many things possible. FormGroups have indeed an addControl method for adding simple FormControls. Afaik FormGroups do not have addFormArray or addFormGroup method. Therefore I need your help.

Following situation:

this.myForm = this.fb.group({
  id: this.fb.control([this.book.id]),
  // or short form `id: [this.book.id],`
});
Run Code Online (Sandbox Code Playgroud)

Adding a simple control at a later point in time is …

angular angular-reactive-forms formarray formgroups

5
推荐指数
1
解决办法
2548
查看次数