【发布时间】:2017-01-23 06:11:12
【问题描述】:
我有两个CSS类名如下
.icon_heart{
color: #bdbdbd;
}
.icon_heart_red{
color:#a6b7d4;;
}
我的 HTML 有一个心形图标
<div class="icon_heart" *ngIf="showheartIcon">
<ion-icon name="heart" (click)="setWishlistTrue(category.product_id);" class="heart"></ion-icon>
</div>
<div class="icon_heart_red" *ngIf="showheartIconRed">
<ion-icon name="heart" (click)="setWishlistFalse(category.product_id);" class="heart"></ion-icon>
</div>
这里有两个 div 标签,心形图标最初是灰色,点击后我会将其更改为蓝色。
这是我的 ts 文件代码:
showheartIcon=true;
showheartIconRed =false;
setWishlistTrue(id){
this.showheartIconRed = true;
this.showheartIcon = false;
}
setWishlistFalse(id){
this.showheartIconRed = false;
this.showheartIcon = true;
}
我有两个不同颜色的图标。
问题
是否可以更改图标的类别而不是两个心形图标?
我在 JavaScript 中看到我们可以更改它w3schools 将类应用于 div 标签的简单方法,但我是 TypeScript 的新手。如何更改班级?
【问题讨论】: