Вы еще не показали, как выглядит ваш массив данных, но допустим, что он выглядит так:
myArray = [
{
name: 'item1',
product_id: 'aaa'
},
{
name: 'item2',
product_id: 'bbb'
}
]
Итак, теперь вы хотите добавить свойство количества, которое вы можете сделать так:
this.myArray = this.myArray.map(item => {
item.quantity = 0
return item
})
Итак, теперь ваш массив выглядит так:
myArray = [
{
name: 'item1',
product_id: 'aaa',
quantity: 0
},
{
name: 'item2',
product_id: 'bbb',
quantity: 0
}
]
Так что теперь вы можете перебирать свой массив в своем шаблоне так:
<ng-container *ngFor="let item of array">
<div class="spinner m-2">
<a class="btn btn-outline-secondary up" (click)="increase(item)">
<i class="ic-add"></i>
</a>
<label id="item-{{item.product_id}}" class="count">
<span>{{ item.quantity }}</span>
</label>
<a class="btn btn-outline-secondary down" (click)="decrease(item)">
<i class="ic-substract"></i>
</a>
</div>
</ng-container>
и в контроллере.ts файл:
increase(item) {
if (item.quantity < this.maxNumber) {
item.quantity ++
}
}
decrease(item) {
if (item.quantity > 0) {
item.quantity --
}
}