Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

111
Views
Mouse wheel directive is not called in Angular 13

I am trying to use mouse wheel directive. This is my first directive, and I can't make it work. This is the directive:

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");
    }
  }
}

And this is how I use it:

<div #htmlDiv wheel class="data-table">
    <table mat-table [dataSource]="dataSource">
        ...
    </table>
</div>

I registered directive in NgModule:

@NgModule({
  declarations: [
    ...
    MouseWheelDirective
  ],
  imports: [
    ...
  ],
  exports: [
    ...
    MouseWheelDirective
  ]
})

In console I see directive was created. But I don't see any messages when I'm scrolling mouse wheel on my table. Could anyone say how to fix it?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

'mousewheel' is deprecated. Use 'wheel' instead. Here is a list of HTML DOM events: https://www.w3schools.com/jsref/dom_obj_event.asp

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!