【发布时间】:2021-04-21 03:40:59
【问题描述】:
我正在用 angular 11 创建这个图片上传组件
我有一个div 和matRipple 的拖放区,所以每当用户拖放文件时,它都会显示涟漪效应。在那个 div 里面我有按钮可以左右旋转。当我单击这些按钮时,也会触发放置区 div 的涟漪效应。
有没有办法禁用它?因此,如果用户单击该 div 中的按钮,该 div 的涟漪效应不会发生?我认为通过将event.stopPropagation() 添加到按钮事件处理程序中它会停止它,但它没有。
这是我的组件:
<div class="container">
<div class="box" style="width: 264px; height: 264px;transition: transform 0.5s" [style.transform]="'rotate(' + this.imageRotation + 'deg)'">
<img style="max-width: 264px; max-height: 264px; position: relative" [src]="selectedFile?.src ? selectedFile?.src : previewImageUrl ? previewImageUrl : null" /></div>
<div class="box stack-top">
<div class="dropzone" comTuxinUpArea (fileDropped)="processFile($event)" matRipple>
<input type="file" id="fileDropRef" accept="image/jpeg,image/png,image/webp" (change)="processFile($event.target)" />
<h3 i18n>drag and drop file here</h3>
<h3 i18n>or</h3>
<label for="fileDropRef" i18n>Browse for file</label>
<div fxLayout="row" fxLayoutAlign="center center" id="rotate-div">
<button mat-icon-button *ngIf="this.selectedFile" (click)="rotateLeft()"><mat-icon>rotate_left</mat-icon></button>
<button mat-icon-button *ngIf="this.selectedFile" (click)="rotateRight()"><mat-icon>rotate_right</mat-icon></button>
</div>
</div>
</div>
旋转按钮事件处理程序:
rotateLeft() {
this.imageRotation+=90;
}
rotateRight() {
this.imageRotation-=90;
}
【问题讨论】:
-
你尝试过 event.stopPropagation() 的 mousedown 吗?
标签: angular angular-material stoppropagation