【发布时间】:2022-01-05 14:30:52
【问题描述】:
我有一个在 ngFor 循环内的按钮。我是这样设计的。
<div *ngFor="let component of componentList;let index =index">
<button type="button" id='Button{{index}}' name='Button{{index}}' class="device_name_button" [ngClass]="{'greencolorstyle':component.status=='Available', 'redcolorstyle': component.status=='Faulted', 'graycolorstyle':component.status=='Unavailable','myClass':isClicked==true}" (click)="selectComponent($event,component.components);" > {{component.name}} </button>
</div>
我正在使用点击事件处理程序设置 isClicked = true。
我的问题是,当我看到按钮上应用的样式时,单击后,我看到 'device_name_button greencolorstyle myClass'。而点击它应该只有 'device_name_button' 和 'myClass'。
当有人单击此按钮时,如何从该按钮中删除其他类?
【问题讨论】:
-
能否添加点击时执行的代码
标签: angular ng-class angular13