在ngFor中获取模板参考

时间:2019-01-28 06:23:34

标签: angular

我正在ngFor中创建

<mat-expansion-panel *ngFor="let relatedDatastore of relatedDatastores">
    <mat-expansion-panel-header >
    </mat-expansion-panel-header>
    <items-grid-component [gridId]="relatedDatastore.d_id" #grids></items-grid-component>
</mat-expansion-panel>

我试图获取那些ItemGridCOmponent以便将它们存储在具有其对应ID的数组中。

ngOnInit(){
    this.relatedGrids = new Map<string, ItemsGridComponent>();
    MyApiCall.subscribe((data:any) =>{
            this.relatedDatastores = data.related_datastores; // I populate the variable for ngFor here

            this.relatedDatastores.forEach(relatedDatastore => { // I want to store my newly create component with the ID of the element here
                let relatedGrid = this.grids._result.find(grid => {return grid.gridId === relatedDatastore.d_id});
                this.relatedGrids.set(relatedDatastore.d_id, relatedGrid);
            })
        }
    });
}

这可以,但是_result是私有的。

我需要使用可观察的东西,但是它开始变得非常混乱...

有没有办法做到这一点?

0 个答案:

没有答案