javascript - make function run when click
问题描述
I want make blink a icon when I click on it
My ts file
onBlink() {
this.action = true;
setTimeout(() => {
this.action = false;
}, 1000)
return this.action
};
My HTML file action is declare in ts as any type
<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>
解决方案
这个想法很好,我只是稍微改变了语法:
<mat-icon
(click)="onBlink()"
class="icon bulb"
[ngClass]="{ 'blink_me': action }">
wb_incandescent
</mat-icon>
````
推荐阅读
- javascript - 精灵在按键时不移动
- reactjs - 带有粗箭头功能组件的 ReactJS 组件生命周期方法
- oracle - 将 oracle 客户端从 win7/32 迁移到 win10/64
- performance-testing - Gatling 可以从一个特征文件中执行多个空手道场景吗?
- visual-studio-code - 出现点或连字符时选择VSCode中的当前单词?
- spring-boot - Spring中的TLS客户端证书认证
- google-bigquery - Google BigQuery - 如何检索外部表的列元数据
- reactjs - 通过 React useState() 处理表单数据的更好方法?
- c++ - Boost::Test 在 Windows 上使用 Clang + CMake:链接错误奇怪
- python-3.x - 如何将变量添加到 xlsxwriter .filter_column