如何突出显示离子列表中的选定项目/项目

2022-01-21 00:00:00 css ionic-framework ionic3

我有一个项目列表显示在屏幕上,只是想在列表视图中突出显示选定的项目/项目,请帮助

I have a list of items populating on a screen and just wanted to highlight the selected item/items in the list view , please help

 <ion-list >
  <button ion-item *ngFor="let route of Routes" (click)="selectCP(route)" >
    {{route.Name}}
  </button>  
 </ion-list>

推荐答案

使用Angular条件样式函数.

Using Angular conditional style function.

[class.stylename]="一些将返回真或假的条件语句"

[class.stylename]="Some conditional statement that will return true or false"

例子:

<!-- This will probably go into your SCSS stylesheet -->
<style>
.highlight {
   background-color: #FFFF33 !important;
}
</style>

<!-- In your HTML code -->
 <ion-list >
  <button ion-item [class.highlight]="route == 1" *ngFor="let route of Routes" (click)="selectCP(route)" >
    {{route.Name}}
  </button>  
 </ion-list>

相关文章