私はそのような別の配列に配列を持っています:
<div class="col-sm-6">
<div formArrayName="site_source_pages">
<div *ngFor="let site_source_page of siteForm.controls.site_source_pages.controls; let x=index">
<div [formGroupName]="x">
<div class="card card-accent-success">
<div class="card-header">
<strong>Yeni Kaynak Sayfa</strong>
</div>
<div class="card-block">
<div class="row">
<!--Site Page Source Form Group-->
<div class="form-group">
<div class="form-group col-sm-6">
<label for="page_url">Sayfa Url</label>
<!--<label *ngIf="!site_source_page.controls[x].controls.page_url.valid" class="text-danger">*</label>-->
<input type="text" class="form-control" id="page_url" placeholder="Badge-Manager" formControlName="page_url">
</div>
</div>
<div class="form-group col-sm-6">
<label for="postal-code">Tarama Aralığı</label>
<input type="text" class="form-control" id="postal-code" placeholder="Badge-Email">
</div>
</div>
<div class="row">
<div formArrayName="page_containers">
<div *ngFor="let page_container of site_source_page.controls.page_containers.controls; let i=index">
<div [formGroupName]="i">
<div class="col-sm-4">
<div class="form-group">
<label for="ccnumber">Container {{i + 1}} Type</label>
<label [hidden]="site_source_page.controls.page_containers.controls[i].controls.container_type.valid" class="text-danger">*</label>
<input type="text" class="form-control" id="container_type" placeholder="Container Type" formControlName="container_type">
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label for="ccnumber">Container {{i + 1}} Selector Type</label>
<input type="text" class="form-control" id="selector_type" placeholder="Container Selector Type" formControlName="selector_type">
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label for="ccnumber">Container {{i + 1}} Css Query</label>
<span class="glyphicon glyphicon-remove pull-right" *ngIf="site_source_page.controls.page_containers.controls.length > 1" (click)="removePageContainer(i)">x</span>
<input type="text" class="form-control" id="container_css_query" placeholder="Container Css Query" formControlName="selector_css_query">
</div>
</div>
<div class="col-sm-12">
<button type="button" class="btn btn-secondary btn-block" (click)="addPageContainer(x)">Container Ekle</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
typescriptを介して2番目の配列にアイテムを追加したい。2 番目の配列 (page_containers) にアクセスしようとしましたが、次のエラーが発生しました。
未定義のプロパティ「コントロール」を読み取ることができません
私の機能はそのようなものです:
addPageContainer(x: number) {
// add container to the list
const controlSp = <FormArray>this.siteForm.controls['site_source_pages'];
const controlPc = <FormArray>controlSp.controls['page_containers'];
controlPc.push(this.initPageContainer());
}
この行で 2 番目のアレイに到達できないのはなぜですか?
const controlPc = <FormArray>controlSp.controls['page_containers'];
何か案が?