Я создаю реактивную форму с параметрами с именем FormBuilder.array. При динамическом создании параметров нет проблем, недостаток заключается в том, как связать его с шаблоном. Любая идея, как это сделать
, переменная val_lista связана с полем списка
agregarParametro() {
let val_lista=this.fb.control({ncodlis:""});
this.parametros.push(
this.fb.group({
ncodpar: "",
objectid: "",
cnompar: "",
ctipdat: "",
nfilini: "",
ckeypar: "",
subprogramid: "",
nordpar: { value: "", disabled: true },
ctippar: { value: "", disabled: true },
cnomaux: ["", [Validators.required, Validators.maxLength(30)]],
listavalores: val_lista,
ctipinf: ""
})
);
}
той частью, где я хочу связать поле ncodlis с шаблоном
<div formArrayName="parametros" *ngFor="let control of parametros.controls; let i = index">
<div class="row" [formGroupName]="i">
<div class="col-md-1">
<mat-form-field appearance="outline" class="full-width">
<mat-label>Orden</mat-label>
<input matInput placeholder="Orden" formControlName="nordpar" />
</mat-form-field>
</div>
<div class="col-md-1">
<mat-form-field appearance="outline" class="full-width">
<mat-label>Tipo</mat-label>
<input matInput placeholder="Tipo parametro" formControlName="ctippar" />
</mat-form-field>
</div>
<div class="col-md-3">
<mat-form-field appearance="outline" class="full-width">
<mat-label>Nombre</mat-label>
<input matInput placeholder="Nombre" formControlName="cnomaux" />
</mat-form-field>
</div>
<div class="col-md-3" >
<mat-form-field appearance="outline" class="full-width">
<mat-label>Valores</mat-label>
<mat-select formControlName="ncodlis"><!--error no reconoce el ncodlist-->
<mat-option>--</mat-option>
<mat-option *ngFor="let l of listas" [value]="l.ncodlis">
{{ l.cdeslis }}
</mat-option>
</mat-select>
</mat-form-field>
</div>
</div>
</div>
ERROR Error: Cannot find control with path: 'parametros -> 0 -> ncodlis'
at _throwError (forms.js:3479)
at setUpControl (forms.js:3303)
at FormGroupDirective.addControl (forms.js:7551)
at FormControlName._setUpControl (forms.js:8367)
at FormControlName.ngOnChanges (forms.js:8288)
at FormControlName.wrapOnChangesHook_inPreviousChangesStorage (core.js:26853)
at callHook (core.js:4690)
at callHooks (core.js:4650)
at executeInitAndCheckHooks (core.js:4591)
at selectIndexInternal (core.js:9621)