Я пытаюсь связать директиву с некоторыми опциями mat для получения событий keydown на них. Директива инициализируется, но не реагирует на события нажатия клавиш. Любая идея, почему функция onKeydown не срабатывает?
Директива
import { Directive, ElementRef, HostListener } from '@angular/core';
@Directive({
selector: '[appSelectTab]'
})
export class SelectTabDirective {
constructor(private el: ElementRef) { console.log('init') }
@HostListener('document:keydown', ['$event']) onKeydownHandler(event:
KeyboardEvent) {
if(event.code.toLowerCase() == "tab"){
//tab performed on the first option in the select list for example
//this.el.nativeElement do something to or with me.
}
//this doesn't work because the listener is fired for all of the mat-options
}
Разметка:
<mat-option appSelectTab *ngFor="let schedule of maintenanceSchedule" [value]="schedule">
{{ schedule }}
</mat-option>
Кроме того, мне нужна опция c mat-option что событие keydown было выполнено.