在这种情况下,我想在数组中实现动态增加减少不计数。。我有一个产品清单,我必须在添加到购物车的项目或减少计数
这是HTML
<div class="add-prdct">
<p (click) = "removeItem(item.id); 'pid = item.id' ">-</p>
<span *ngIf="item.id === pid && isclicked === true">{{ itemCount }}</span>
<span *ngIf="isclicked === false">1</span>
<p (click) = "addItem(item.id); 'pid = item.id'">+</p>
</div>
Here item coming From the ngFor Loop
TS公司
addItem(id: any, index: any): void {
this.itemCount++;
this.pid = id;
this.isclicked = true;
// this.itemCount = this.itemCount + 1;
}
removeItem(id: any, index: any): void {
this.pid = id;
if (this.itemCount === 1) {
this.itemCount = 1;
} else {
this.itemCount--;
}
}
And itemCount = 1
initialized
The Problem is when i am increasing in a product the in other product the {{ itemCount }}
its not holding the 1 value
救命