Answer the question
In order to leave comments, you need to log in
How to get DOM element on event in Anuglar?
There is such a method in the project component on Angular 11, which listens for keystrokes on the keyboard
@HostListener('document:keydown', ['$event'])
public someMethod(event: KeyboardEvent) {
console.log('event', event);
}
Answer the question
In order to leave comments, you need to log in
If I use the event.target property, I get a field of type EventTarget that does not have any properties
@HostListener('document:keydown', ['$event', '$event.target'])
public someMethod(event: KeyboardEvent, target: HTMLElement) {
console.log('event', event, target);
}
constructor(private el: ElementRef) { }
Then use likethis.el.nativeElement
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question