我有一个具有引导下拉列表的组件,我想关注下拉范围内设置的当前周
我可以通过设置 ids 使用纯 javascript 来完成此操作,然后使用 Jquery .focus() 方法来关注它,但想知道是否有任何 Angular 7/ 7+ 方法可以使用 ViewChildren 等来完成此操作。
<button class="btn dropdown-toggle"
(click)="focusOnWeek(currentWeek)"
type="button" data-toggle="dropdown">
<span>Week {{currentWeek}}</span> // currentWeek = 5 need to focus on week 5 <a> tag on click of this span
</button>
<ul class="dropdown-menu">
<li *ngFor="let week of weekList">//weekList = [1,2,3,4,5,6,7,8,9,10]>
<a class="dropdown-item"
Week {{week}}
</a>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
单击按钮后,当前周将成为焦点。