[英]Angular how to find which element in QueryList<ElementRef> is clicked
I have ElmentRef(QueryList) of set of Table cells (td html elements-dynamically created) using ViewChildren.我有一组使用 ViewChildren 的表格单元格(td html 元素-动态创建)的 ElmentRef(QueryList)。 I debugged and have the element set available.
我调试并有可用的元素集。
When I click on a particular td html element I call a function and in that function I need to find which element in ElementRef(QueryList) is clicked.当我单击特定的 td html 元素时,我调用了一个函数,在该函数中,我需要找到 ElementRef(QueryList) 中的哪个元素被单击。 How can I do this?
我怎样才能做到这一点?
component.html组件.html
<table>
<tr *ngFor="let i of Arr">
<ng-container *ngFor="let j of Arr">
<td #tdID (click)="cellClicked(tdID)">
</td>
</ng-container>
</tr>
</table>
component.ts组件.ts
Arr =[1,2,3];
@ViewChildren('tdID') divs:QueryList<ElementRef>;
cellClicked(cell) {
console.log("Cell clicked"+cell);
//Help find here which element in the divs QueryList matches "cell"
}
<table>
<tr *ngFor="let i of Arr">
<ng-container *ngFor="let j of Arr">
<td #tdID (click)="cellClicked(tdID, i, j)">
</td>
</ng-container>
</tr>
</table>
In you .ts file在你的 .ts 文件中
cellClicked(tdID, i, j) {
console.log(tdID, i, j)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.