如何在nativescript中应用NgClass中的背景色属性



如果我给类提供背景颜色属性,但当我选择布局颜色时,它不会改变。

enter code here
<StackLayout verticalAlignment="middle"   [ngClass]="{'iconLayout':  item.selected}" class="backWhiteSelect"   (tap)="drinkSelected(i)"></stackLayout>
CSS:
.iconLayout{
margin: 5;  
height: 90;
width: 185;
text-align: center;
border-radius: 7;
background-color: rgba(112, 112, 112, 0.15);
}

使用ngClass 添加新的StackLayout

<ng-template let-item="item" let-i="index">
<StackLayout verticalAlignment="middle">
<StackLayout [ngClass]="item?.selected ? 'backWhiteSelect' : 'iconLayout'" (tap)="onTap(item)">
<Label [text]="item?.name" class="text-center gray-66 h3"></Label>
</StackLayout>
</StackLayout>
</ng-template>

组件中的tap事件

onTap(item) {
this.interestsItems.forEach(m => m.selected = false);
item.selected = true;
}

最新更新