angular - Angular mouseover 和 mouseout 仅在列表中的一个上
问题描述
<div class="col-sm-2" style="margin-top: 15px;" *ngFor="let song of librarySongs">
<div id="container" (mouseover)="options=true" (mouseout)="options=false">
<img style="border-radius: 3px;" [src]="song.url" height="135px" width="135px">
<div id="example" *ngIf="options">
<span style="float: left;color:#2cd4bb;font-size: 12px">ASSIGN</span>
<span style="float: right;color:#2cd4bb; font-size: 12px; ">DELETE</span>
</div>
</div>
</div>
TS-
options: boolean;
ngOnInit(): void {
this.options = false;
}
这是我的代码。鼠标悬停和鼠标悬停工作正常。唯一的问题是我有来自后端的歌曲列表,当我将鼠标悬停在其中任何一个上时,所有其他鼠标悬停也可见。我们如何将其更改为,当我将鼠标悬停在一个列表项上时,鼠标悬停应该是可见的,而不是所有的?
解决方案
您应该添加选项也不是全局的每个项目,并将选项参数添加到 librarySongs 数组的对象作为默认值false
<div class="col-sm-2" style="margin-top: 15px;" *ngFor="let song of librarySongs">
<div id="container" (mouseover)="song.options=true" (mouseout)="song.options=false">
<img style="border-radius: 3px;" [src]="song.url" height="135px" width="135px">
<div id="example" *ngIf="song.options">
<span style="float: left;color:#2cd4bb;font-size: 12px">ASSIGN</span>
<span style="float: right;color:#2cd4bb; font-size: 12px; ">DELETE</span>
</div>
</div>
</div>
推荐阅读
- android - 如何以编程方式将文本元素添加到我的小部件/类?
- opencv - OpenCV VideoWriter 不写入 Output.avi
- javascript - Ajax/PageMethod 都返回完整页面 HTML 而不是执行 webmethod 并正确返回
- angular - 如何将复选框动态添加到角度形式(Angular 4)
- tensorflow - 为什么在训练我的模型时我在 Keras 中的损失没有改变?
- php - Silverstripe 4 中的 GroupedList,按 many_many_extrafield 分组
- node.js - 如何解析带有文件路径作为变量之一的查询字符串并使用该文件路径变量下载文件?
- android - Python 3 的 Kivy Buildozer 要求错误
- c# - 使用 Linq 查找具有属性的构造函数
- linux - 执行 JAR 文件后如何在命令行中仅模拟一个 ENTER