【发布时间】:2019-04-13 20:38:08
【问题描述】:
我的html代码:
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-4 col-lg-12">
<ng-container *ngFor="let horizontal of categories">
<ng-container *ngFor="let horizontalval of horizontal.items;let i=index">
<button [ngClass]="{'selected-color' : i==selectedIndex}" type="submit" class="btn1" [id]="horizontal.items[i].title" (click)="changeTrans(horizontal.items[i].title);changeColor(i)">
<img [src]= horizontal.items[i].icon alt="image not found" class="icon"/>
{{ horizontal.items[i].title }}
</button>
</ng-container>
</ng-container></div>
</div>
所以我的 component.ts 文件,
changeColor(i){
console.log(i);
this.selectedIndex = i;
}
我的CSS:
.selected-color{
background-color: orange;
color:white;
// background-image: url('./../../../../../assets/Trans_1.png');
}
所以在这里我可以更改所选按钮的颜色,但我还需要为不同的值更改不同的图像。在这里,如何为每个按钮 ID 动态更改我的图像?
基本上我想知道的是,如何为将要通过 for 显示的每个按钮动态更改图像。谁能给我一些建议来实现它?
【问题讨论】:
标签: html css angular angular5 angular6