Angular 如何在单击另一个标签标签时删除活动类
我有一个div标签,循环到每个产品的价格,和 单击产品价格将活动类设置为其标签元素标记 我的问题是,如果单击另一个label元素,如何删除活动类Angular 如何在单击另一个标签标签时删除活动类,angular,Angular,我有一个div标签,循环到每个产品的价格,和 单击产品价格将活动类设置为其标签元素标记 我的问题是,如果单击另一个label元素,如何删除活动类 <div class="btn-group cx-cont" *ngFor="let price of product.price" data-toggle="buttons" > <label class="btn btn-primary " id="cart-label" [ngClass]="{'active' : pr
<div class="btn-group cx-cont" *ngFor="let price of product.price" data-toggle="buttons" >
<label class="btn btn-primary " id="cart-label" [ngClass]="{'active' : price.active == true }">
<input type="radio" class="cart-check" ng-class="{'active': isActive}" (click)="selectProduct(price.id,price, price.unit)" autocomplete="off">
<div class="cart-price">{{price.price | currency: 'USD':true}}</div> <div class="cart-unit">{{price.unit}}</div>
</label>
</div>
}实现这一目标的方法之一是:
[ngClass]="price.active ? 'active' : ''"
只需存储
active\u price\u id
并在模板{'active':active\u price\u id==price.id}
中,active\u price\u id的初始值应该是什么?如果要使所有标签处于非活动状态->应用程序中肯定不存在的某个id。如果priceId
是sql的autoincrement
索引,那么您可以设置“-1”,例如。或者将变量类型设为any
(如果您使用typescript),并将null
。。。
[ngClass]="price.active ? 'active' : ''"