實(shí)際上我想根據(jù) id 減去數(shù)量。當(dāng)用戶單擊“A”上的按鈕時,“A”的數(shù)量應(yīng)該減少 1。此演示代碼stackblitzHTML<p *ngFor="let item of arrayOfArray"> Name: {{item.name}} Quantity: {{item.quantity - currentIndex}} <button (click)="addItem(item)">minus Quantity</button></p>成分public currentIndex = 0; arrayOfArray = [ {id: '1', name: 'A', quantity: '12'}, {id: '2', name: 'B', quantity: '29'}, {id: '3', name: 'C', quantity: '21'}, {id: '4', name: 'D', quantity: '11'} ] addItem(val){ if(val.id){ this.currentIndex += 1; } }
根據(jù) id 減去數(shù)量
阿晨1998
2023-03-18 11:03:11