Property 'clientX' does not exist on type 'Event'. Angular2 Directive
14,534
Change the parameter type
onMousemove(event: MouseEvent): void {
console.log(event.clientX)
}
Related videos on Youtube
Author by
Nate May
5 years Army Infantry | Deployments (2): Baghdad, Kandahar University of Illinois | Majors (2): Accounting, Finance - Minors (2): Technology & Management, Informatics Deloitte Consulting | intern FTI Consulting | Data Consultant TATA Consulting | Web Developer (Angular, Jquery) CitiGroup | Development Team Lead (Angular) University of Michigan | MS Information - Minor Entrepreneurship
Updated on December 13, 2020Comments
-
Nate May over 3 years
I'm trying to listen to the X position of my mouse in an Angular2 Directive like this:
@HostListener('mousemove', ['$event']) onMousemove(event: Event): void { console.log(event.clientX) }
but I get the error
Property 'clientX' does not exist on type 'Event'.
This is odd because this listener
@HostListener('mousemove', ['$event']) onMousemove(event: Event): void { console.log(event) }
logs out an event object
Why can I not access
event.clientX
? -
Diego Ortiz over 4 yearsI have a similar issue, I tried with several different types, including
MouseEvent
that is the one I get in my console.log() but it keeps saying:Property 'layerY' does not exist on type 'MouseEvent'
-
Günter Zöchbauer over 4 yearsInteresting. It not a standardized property but according to developer.mozilla.org/en-US/docs/Web/API/UIEvent/layerY all browsers support it. Check your browsers changelog if it was discontinued there.