angular - 如何在鼠标事件绑定中传递参数
问题描述
我使用基于行和列索引的参数为每个单元格渲染表格并添加(mouseenter)事件。
<table>
<tr *ngFor="let row of rows; let rowIndex = index;">
<td *ngFor="let column of columns; let columnIndex = index;"
(mouseenter)="mouseEnterHandler(rowIndex, columnIndex)">
</td>
</tr>
</table>
mouseEnterHandler(rowIndex, columnIndex) {}
但是,这会导致性能问题,这就是为什么我想使用 ngZone 在 angular 之外运行 mouseenter。
this.zone.runOutsizeAngular(() => {
this.element.nativeElement.addEventListener('mouseenter', this.mouseEnterHandler.bind(this));
});
但是现在我将无法访问当前的 mouseenter 行和列索引。是否可以在鼠标输入事件期间获取这些参数?
解决方案
在你的功能中,你可以做这样的事情
mouseEnterHandler(rowIndex, columnIndex){
console.log(rowIndex);
console.log(columnIndex);
}
推荐阅读
- python - 烧瓶管理员记住表单值
- android - 找不到 io.fabric.tools:gradle:1.28.1
- tensorflow - 在 Cifar10 数据上比较 Pytorch 和 Keras 的例子
- android - 如何在不将这些更改反映到原始对象的情况下复制伴随对象并进行更改?
- javascript - 更新对象数组中的属性
- mysql - SQL 输出将列转换为行
- maven - 如果不指定 maven 插件的版本会怎样?
- python - Python打印到文件功能没有打印到文件
- node.js - 为什么在正确执行入职流程后,目的地收费、条带连接时出现“没有此类帐户”错误?
- angular - 如何在 Angular Typescript 中订购 FireStore 集合