1
Good afternoon,
I would like an orientation, I am learning from Ionic and assembling an application, on my main page there is the following code:
<form>
<ion-card class="cardsIndex" *ngFor="let produto of produtos; let i = index">
<img src="{{produto.imagem}}"/>
<ion-card-header class="cardHeader">
<ion-card-title><b>{{produto.nome}}</b></ion-card-title>
<ion-label><b>Estoque:</b> {{produto.quantidade}}</ion-label>
</ion-card-header>
<ion-card-content class="cardsInputs">
<ion-button (click)="comprarButton(produto.id)" >Comprar</ion-button>
<ion-input class="inputHome" type="number" min="0" [(ngModel)]="comprarQtd" name="produto{{i+1}}" placeholder="Quantidade"></ion-input>
</ion-card-content>
</ion-card>
</form>
I’m consulting a json-server and getting product information. Each "Card" has a field for the purchase and the input field that will be placed the amount that the user wants to buy. However, when placing the value in any of the input fields, they all take the same value.
In the component class of this page, there is the variable:
comprarQtd: number;
I know what is wrong is that it is assigning to ALL fields the same value that is being indicated in this variable above. However, you would know how to guide me how I can assign each Input value to its given variable and it does not assign to all fields at the same time?
Thank you very much!
Man, thank you so much for your help! I applied your example and helped me perfectly in what I needed! Thank you very much!
– Dennis Cezar
Jewel that helped man, success!
– LeAndrade