I am attempting to create a button that can be used to increment and decrement. However, I am facing an issue where all input fields are being affected instead of just one.
This is the code in body.component.html
<div class="items-detail-detail" *ngFor="let detail of card.detail">
<div class="items-detail-information3">
<div class="btn-block" >
<button class="btn btn-default" (click)="onDecrement()">
<i class="material-icons">remove</i>
</button>
</div>
<div class="input-group" >
<input type="number" value="{{counter}}" class="form-control" style="text-align:center;" >
</div>
<div class="btn-block">
<button class="btn btn-default" (click)="onIncrement()">
<i class="material-icons">add</i>
</button>
</div>
</div>
This is the code in body.component.ts
export class BodyComponent implements OnInit {
private counter : number = 0;
onIncrement() {
this.counter++
}
onDecrement() {
this.counter--
}
ngOnInit() {
}}
The current behavior of the code is shown in the image below:
When clicking the [+] button at the top, it increments all input fields as shown here:
Apologies for any language barriers, thank you for your assistance.
Appreciate it!