【发布时间】:2021-06-24 10:22:26
【问题描述】:
我正在尝试通过箭头键选择 li,但遇到了问题。
我尝试关注here的答案,但我的 li 从未被选中。
对于下面的代码,我只是想让 (keydown) 工作。
这是我的:
landingpage.component.html
<div class="searchArea">
<input type="text" autoComplete="off" (keydown)="keyDown($event)" placeholder={{backgroundPlaceholder.info.placeholderText}} [(ngModel)]="keystroke"
(ngModelChange)="getKey($event)">
<div class="results-list">
<li *ngFor="let list of shows; let i = index" [class.active]="i == {{arrowkeyLocation}}">
<span class="result">{{list.show}}</span>
</li>
</div>
</div>
landingpage.component.ts
arrowkeyLocation = 0;
keyDown(event) {
return this.arrowkeyLocation++;
}
按原样,当我按下向下键时没有选择任何内容。我很确定问题出在我的 html [class.active] 中,但我不确定如何解决。
如何通过方向键选择 li 元素?
【问题讨论】:
标签: javascript html angular html-lists