angular - 在 ngFor 中获取模板引用
问题描述
我在 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 是私有的。
我需要使用可观察的,但它开始变得非常混乱......
有没有办法以不同的方式做到这一点?
解决方案
推荐阅读
- numpy - 在 python 中使用直接线性变换进行相机校准
- python - 使用 numpy 时出现错误,没有名为“matplotlib.pylot”的模块
- excel - VBA 中的参数不正确
- javascript - 打开 DrawerNavigation 时自动调用 API
- bash - (参数列表太长)使用 *cat* 打开大量文件时
- python - django allauth - get() 返回了多个用户——它返回了 2 个!在生产中
- python - 使用 Python 使用带有 Quectel EC25 的 Raspberry pi 自动回复 SMS
- php - cURL 错误 7:无法连接到“x.xx.xxx.xx”端口 9090:连接被拒绝
- java - 如何在java的主类中调用键盘类
- python - 无法从“asyncio”导入名称“get_running_loop”