Angular 2/4 Edit Form Populate FormArray Controls

前端 未结 2 1005
野的像风
野的像风 2021-02-04 06:40

I\'m trying to implement an edit form for a model with nested attributes (FormArray). I\'m having trouble with the syntax and I\'m uncertain whether I\'m on the right track. Th

2条回答
  •  星月不相逢
    2021-02-04 07:22

    If I understand your question correctly, you may need something like this:

        // Update the data on the form
        this.productForm.patchValue({
            productName: this.product.productName,
            productCode: this.product.productCode,
            starRating: this.product.starRating,
            description: this.product.description
        });
        this.productForm.setControl('tags', this.fb.array(this.product.tags || []));
    

    You can see the complete example here: https://github.com/DeborahK/Angular2-ReactiveForms in the APM - Updated folder.

提交回复
热议问题