我正在嘗試使用滑鼠滾輪指令。這是我的第一個指令,我無法讓它發揮作用。這是指令:
import { Directive, ElementRef, HostListener } from "@angular/core";
@Directive({
selector: '[wheel]'
})
export class MouseWheelDirective {
constructor(private el: ElementRef) {
console.log("directive was created");
}
@HostListener('mousewheel', ['$event'])
onMousewheel(event) {
console.log("event");
if (event.wheelDelta > 0) {
console.log("wheel 0");
}
if (event.wheelDelta < 0) {
console.log("wheel 1");
}
}
}
這就是我使用它的方式:
<div #htmlDiv wheel class="data-table">
<table mat-table [dataSource]="dataSource">
...
</table>
</div>
我在 NgModule 中注冊了指令:
@NgModule({
declarations: [
...
MouseWheelDirective
],
imports: [
...
],
exports: [
...
MouseWheelDirective
]
})
在控制臺中我看到directive was created. 但是當我在桌子上滾動滑鼠滾輪時,我沒有看到任何訊息。有人能說如何解決嗎?
uj5u.com熱心網友回復:
'mousewheel' 已被棄用。改用“輪子”。以下是 HTML DOM 事件串列: https ://www.w3schools.com/jsref/dom_obj_event.asp
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/477920.html
標籤:javascript 有角度的 打字稿
上一篇:使用打字稿渲染道具
