Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何在单击另一个标签标签时删除活动类_Angular - Fatal编程技术网

Angular 如何在单击另一个标签标签时删除活动类

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标签,循环到每个产品的价格,和 单击产品价格将活动类设置为其标签元素标记

我的问题是,如果单击另一个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' : 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' : ''"