gpt4 book ai didi

javascript - 让函数在点击时运行

转载 作者:行者123 更新时间:2023-11-28 03:33:10 26 4
gpt4 key购买 nike

我想让图标在点击时闪烁

我的ts文件

  onBlink() {
this.action = true;
setTimeout(() => {
this.action = false;
}, 1000)
return this.action
};

我的 HTML 文件action 在 ts 中声明为任意类型

<td mat-cell *matCellDef="let element">
<mat-icon (click)="element.action = onBlink()" class="icon bulb"
[ngClass]="{
'blink_me': element.action ,
'': element.action === false}
">wb_incandescent</mat-icon>
</td>


最佳答案

您需要将元素从 html 传递到 ts:

<mat-icon (click)="onBlink(element)" class="icon bulb" [ngClass]="element.action ? 'blink_me': ''">wb_incandescent</mat-icon>

然后在你的ts中:

onBlink(element) {
element.action = true
console.log('blink true');
setTimeout(() => {
element.action = false;
console.log('blink false')
},1000)
}

关于javascript - 让函数在点击时运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57977626/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com