2017-02-21 72 views
0

我有一个div标签,该标签循环到每个产品的价格,并 点击产品价格设置活动类到它的标签元素标记删除活动类。如何在点击进入另一个标签标记

我的问题是我怎么能清除活性类,如果我点击进入另一个标签元素?

<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> 

我有price.active被设置成它[ngClass]="{'active' : price.active == true }"是在selectProduct方法

selectProduct(id, price, unit) { 
this.price_id = id; 
this.price = price; 
this.price.active = true; 
this.unit = unit; 
this.isClassVisible = true; 
this.selectedProd = true; 
// console.log(this.cart); 

}

+0

只是存储'active_price_id'和模板'{ '活动':active_price_id == price.id}' –

+0

什么应该是active_price_id的初始值? – dashred

+0

如果你想使所有'label's无效 - >部分的ID绝对不能在应用程序中存在。如果'priceId'是SQL的'autoincrement'指数,那么你可以设置为“-1”,例如。或者让你的变量类型any'的'(如果您使用的打字稿),并分配'null' ... –

回答

0

的实现这一目标的途径之一就是组件:

[ngClass]="price.active ? 'active' : ''" 
相关问题