在Angular中突出显示列表中的选定项可以通过以下步骤实现:
selectedItem: any = null;
<ul>
<li *ngFor="let item of items" (click)="selectItem(item)" [class.selected]="item === selectedItem">
{{ item }}
</li>
</ul>
selectItem(item: any): void {
this.selectedItem = item;
}
.selected {
background-color: yellow;
}
通过以上步骤,当用户点击列表中的项时,该项将突出显示为黄色背景,表示为选定项。请注意,以上代码示例中的items变量表示列表数据,可以根据实际情况进行替换。
推荐的腾讯云相关产品:腾讯云云服务器(CVM)
领取专属 10元无门槛券
手把手带您无忧上云