如何在nativescript的NgClass中应用背景色属性?
如果我给类赋予背景色属性,但当我选择该布局时,颜色不会改变如何在nativescript的NgClass中应用背景色属性?,nativescript,nativescript-angular,Nativescript,Nativescript Angular,如果我给类赋予背景色属性,但当我选择该布局时,颜色不会改变 enter code here <StackLayout verticalAlignment="middle" [ngClass]="{'iconLayout': item.selected}" class="backWhiteSelect" (tap)="drinkSelected(i)"></stackLayout> CSS: .iconLayout{ margin: 5;
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);
}
在此处输入代码
CSS:
.我的布局{
保证金:5;
身高:90;
宽度:185;
文本对齐:居中;
边界半径:7;
背景色: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>
代码不完整,请尝试在可复制问题的位置共享示例。以下是代码示例。如果我选择名称,背景颜色将不会更改。您确定共享了正确的版本吗?我没有看到任何事件侦听器或iconLayout应用于代码中的任何列表项。但我看到了该列表,我在CSS文件中提供iconLayout,并希望在单击该项目后更改CSS,但除背景色外,所有属性均已应用..当您打开所选标志时,在游乐场中它始终为false。谢谢,当选择1个选项时是有效的,但当您选择多个选项时,它们没有被应用。您可以删除多个选项的“this.interestItems.forEach(m=>m.selected=false);”。
onTap(item) {
this.interestsItems.forEach(m => m.selected = false);
item.selected = true;
}