ngModel is showing the wrong input values

Asked

Viewed 50 times

1

I have an ngFor that runs through an array Products.

Inside this array has the field: value_venda_current, I am trying to make a *ngFor to go through this array and show an input for each product, but it is showing the wrong values in the input. All inputs have the same value as the last element of the array.

I tried something like:

<div *ngFor="let produto of produtosConfirmadosAnuncio; let i = index" class="col-xl-4">
    <div class="col-12 centralizaTexto" *ngFor="let variacao of produto.variacao; let j = index">
        <p class="card-text"><strong>Variação {{j+1}}</strong></p>
        <div class="row inline">
            <div *ngFor="let atributosvariacao of variacao.atributo" class="col-6">
                <p><strong>{{atributosvariacao.valor_atributo.item_atributo.item}}</strong></p>
                <p>{{atributosvariacao.valor_atributo.valor}}</p>
            </div>
        </div>
    </div>

   <div class="col-xl-6">
        <input currencyMask [options]="{ prefix: 'R$ ', align: 'left', thousands: '.', allowNegative: false, allowZero: false, decimal: ',' }" name="valorb2w" required [(ngModel)]="produto.valor_venda_atual" type="text" class="form-control">
        <h6 *ngIf="produto.valor_venda_atual == null && submited" class="input-invalido animated shake">Valor obrigatório.</h6>
   </div>

I am declaring the array this way:

produtosConfirmadosAnuncio: any[] = []
  • It seems that the code is right, which leads me to believe that the problem is with the way the array produtosConfirmadosAnuncio is loaded. You can give more details about this?

  • @Nizer added all the flow here

1 answer

1


I discovered, when a *ngFor is iterated on inputs, the Names should be different, I put it in the name="xxx{{Indice}}" and it worked

Browser other questions tagged

You are not signed in. Login or sign up in order to post.