如何推送formGroup的值,这是一个formArray

时间:2018-05-02 17:51:27

标签: angular5 angular-reactive-forms angular4-forms

我将我的importantOwners作为一个数组,我将地址作为一个formGroup,一旦服务给我数据,我想将从服务中获得的值推送到表单中,我该怎么做?

this.significantOwnersForm = fb.group({
    significantOwners: this.buildSignificantOwnerArray()
});

buildSignificantOwnerArray() {
    this.significantOwners = this.fb.array([this.buildSignificantOwnerGroup()]);

    return this.significantOwners;
}

buildSignificantOwnerGroup() {
    return this.fb.group({
        name: '',
        address: this.fb.group({
            addressLine1: '',
            addressLine2: '',
            addressLine3: '',
            addressLine4: '',
            addressLine5: '',
            city: '',
            state: '',
            postalCode: '',
            countryCode: ''
        })
    });
}

setSelectedSignificantOwnersInformation() {
    let selectedMerchantsSignificantOwners = this.merchantInfo[this.selected[0].merchantNumber].significantOwners;
    let significantOwnersFGs = selectedMerchantsSignificantOwners.map(owner => this.fb.group(owner));
    let significantOwnerFormArray = this.fb.array(significantOwnersFGs);

    this.significantOwnersForm.setControl('significantOwners', significantOwnerFormArray);
}

我收到错误 错误错误:找不到路径控件:'significantOwners - > 1 - >地址 - > addressLine1'

找不到地址的任何内容。

更新: 显示错误

MdfComponent.html:1866 ERROR Error: Cannot find control with path: 'significantOwners -> 0 -> address -> addressLine1'
    at _throwError (forms.js:2432)
    at setUpControl (forms.js:2300)
    at FormGroupDirective.addControl (forms.js:6658)
    at FormControlName._setUpControl (forms.js:7308)
    at FormControlName.ngOnChanges (forms.js:7221)
    at checkAndUpdateDirectiveInline (core.js:12365)
    at checkAndUpdateNodeInline (core.js:13893)
    at checkAndUpdateNode (core.js:13836)
    at debugCheckAndUpdateNode (core.js:14729)
    at debugCheckDirectivesFn (core.js:14670)

0 个答案:

没有答案