【发布时间】:2021-04-01 17:19:19
【问题描述】:
为什么焦点会出错?错误是“EventTarget”类型上不存在属性“焦点”。ts
请任何人帮助我。
@HostListener('keydown.tab', [ '$event'])
keyfunction(event: KeyboardEvent): void {
// First element: always first element is h2 where tabindex avaliable.
let focusable = document.querySelector('.modal').querySelectorAll('[tabindex],button');
if (focusable.length) {
const first = focusable[0];
const last = focusable[focusable.length - 1];
const shift = event.shiftKey;
if (shift) {
if (event.target === first) {
last.focus();// **Error is: Error is Property 'focus' does not exist on type **
event.preventDefault();
}
} else {
if (event.target === last) {
first.focus();// Getting error is here
event.preventDefault();
}
}
}
【问题讨论】:
-
请告诉我有什么问题?
标签: javascript angularjs typescript