使用嵌套表单数组获取“路径错误”

时间:2018-10-23 07:19:18

标签: javascript html angular forms

我有以下html:

<form [formGroup]="customFieldForm">
                 .......... 
      <div formArrayName="FieldNames">
           <div *ngFor="let fieldName of customFieldForm.get('FieldNames').controls; let i = index" 
           [formGroupName]="i">
               <mat-form-field>
                <input matInput [value]="fieldName.value.CustomFieldName"
                [formControlName]="CustomFieldName"
                [placeholder]="placeHolderInLocalLanguage">
          </mat-form-field>
       </div>
    </form

我遇到以下错误:

Cannot find control with path: 'FieldNames -> 0 (and all the length of the array...) -> 

TS文件:

        this.customFieldForm = new FormGroup({
        Menu: new FormControl(null, Validators.required),
        FieldType: new FormControl(null, Validators.required),
        FieldNames : new FormArray([]),
        OptionalOrMendatory: new FormControl(false),
        LineTypes: new FormControl(null),

    })

服务器数据的初始化:

this.data.forEach(nameAndLanguage => {
const FieldName: FormGroup = this.fb.group({
    CustomFieldName: nameAndLanguage.CustomFieldName,
    ID: nameAndLanguage.LanguageID
});
(<FormArray>this.customFieldForm.get('FieldNames')).push(FieldName);
})

任何人都可以在这里发现我做错了吗?

感谢任何试图提前提供帮助的人!

1 个答案:

答案 0 :(得分:0)

我发现了问题:

stages:
- test
test_ba_bpmm_qaa-jb:
stage: test
tags:
- qa-api-automation

script:
- echo "-------------Running maven command to run jmeter tests---------"
- pwd 
- mvn clean install
- echo "-------------------Execution completed---------"
- cd target/jmeter
- pwd
- zip -r bpm_api_testresult.zip reports
- echo "This is the message body" | swaks --to abc@xyz.com --from 
"contact@xyz.com" --server 192.178.176.45 --auth LOGIN --auth-user 
"qauser1@sip.test" --auth-password "abc123" --attach 
"bpm_api_testresult.zip"
allow_failure: false
only:
- master

错误地尝试绑定到属性。