Updated:
In Angular 10, want to display/hide a button base on a boolean value. Code like below:
<button mat-icon-button *ngIf="isOnFocus">
<mat-icon (click)="copyContent()">content_copy</mat-icon>
</button>
<div (focusout)="blur($event)" >{{content}}</div>
Before clicking the button, the focus was on div
element. The click event on mat-icon
can not be triggered when the button displayed.
Try to set the trigger
to the button
instead of content
.
<button mat-icon-button [hidden]="!isOnFocus" (click)="copyContent()">
<mat-icon>content_copy</mat-icon>
</button>
Event execution order: mousedown -> blur -> mouseup ->click
. Changed click
to mousedown
, and moved the click event to <button>
tag as BadPiggie suggested, all works fine.
<button mat-icon-button *ngIf="isOnFocus" (mousedown)="copyContent()">
<mat-icon >content_copy</mat-icon>
</button>
<div (focusout)="blur($event)" >{{content}}</div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.