首页 > 解决方案 > 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>


标签: javascriptangular

解决方案


这个想法很好,我只是稍微改变了语法:

<mat-icon
  (click)="onBlink()"
  class="icon bulb"
  [ngClass]="{ 'blink_me': action }">
  wb_incandescent
</mat-icon>
````

推荐阅读