Angular2 patchValue push value into array

前端 未结 4 449
南笙
南笙 2020-12-30 02:41

Is it It looks like Angular2\'s FormGroup.patchValue() doesn\'t push new elements into an array.

For example something like this:

ngOnInit() {

             


        
4条回答
  •  天涯浪人
    2020-12-30 03:11

    Well, as silentsod said, it is not possible. Currently, I am using below as an alternative:

            let controlArray = this.form.controls['apps'];           
            this.list.forEach(app => {
                        const fb = this.buildGroup();
                        fb.patchValue(app);
                        controlArray.push(fb);
                });
    

    Angular Team - We need a new function something like PatchArray() that would patch from a collection/object graph. It is a basic use case.

提交回复
热议问题