Name is not fixed in variable

1

Good morning! I have a search that I put the names of some products in a variable, but if I search for another product, it subscribes the new product in the old one, like this:

Product search:

2ndProductSearch:

Asyoucansee,itreplacesthevalueofthesecondofthefirst,andIevenunderstandthereason,butIdonotknowhowtosolveit...Note:it'sjusttheproductname.

ProductSearchCode:

case'nomeProduto':params=params.set('cod',formGroup.controls['codigoProduto'].value);this.retornaNomeApi(NEGOCIUS_API+'/Pesquisa/RetornaNome',params).subscribe(nome=>formGroup.patchValue({nomeProduto:nome.result}));break;

Pagets:

Codigo:any;digitacaoForm:FormGroup;itens:ItemPedidoModel[]=[];nomeProd:Produto[]=[];ngOnInit(){this.sub=this.route.queryParams.subscribe(params=>{this.type=params['type'];});this.digitacaoForm=this.fb.group({pedido:this.fb.control('',Validators.required),codigoCliente:this.fb.control('',Validators.required),nomeCliente:this.fb.control({value:'',disabled:true}),rep:this.fb.control('Selecione...',Validators.required),tipoped:this.fb.control('Selecione...',Validators.required),prazo:this.fb.control('Selecione...',Validators.required),forma:this.fb.control('Selecione...',Validators.required),codigoProduto:this.fb.control('',Validators.required),nomeProduto:this.fb.control({value:'',disabled:true},Validators.required),Quantidade:this.fb.control('',Validators.required),precoTabela:this.fb.control({value:'',disabled:true},Validators.required),PrecoDigitado:this.fb.control('',Validators.required),precoTotal:this.fb.control({value:'',disabled:true},Validators.required),});}retornaApi(url:string){returnthis.http.get<any>(url);}GerarCodigo(){this.retornaApi(API+'/Pedido/GerarCodigoPedido').subscribe(codigo=>(this.Codigo=codigo))}pegaNome(formGroup:FormGroup){this.nomeProd=Object.assign('',formGroup.controls['nomeProduto'].value);returnthis.nomeProd;}excluirLinha(codigo:any){for(letitemofthis.itens){if(item.codigoProduto==codigo){this.itens.splice(this.itens.indexOf(item),1);break;}}}

TableHTML:

<divclass="col-md-12">
  <div *ngIf="itens.length" class="table-responsive">
    <table class="table">
      <thead class="thead-dark">
        <tr>
          <th></th>
          <th class="text-center">Código</th>
          <th class="text-center">Descrição</th>
          <th class="text-center">Quantidade</th>
          <th class="text-center">Preço Digitado</th>
          <th class="text-center">Preço Total</th>
        </tr>
      </thead>
      <tbody>
        <tr *ngFor="let item of itens">
          <th class="text-center">
            <button type="button" class="btn btn-danger" (click)="excluirLinha(item.codigoProduto)">
              <i class="glyphicon glyphicon-remove"></i>
            </button>
          </th>
          <td class="text-center">{{item.codigoProduto}}</td>
          <td class="text-center">{{nomeProd}}</td>
          <td class="text-center">{{item.Quantidade}}x</td>
          <td class="text-center">{{item.PrecoDigitado | currency: 'BRL': true}}</td>
          <td class="text-center"></td>
        </tr>
      </tbody>
    </table>
  </div>
</div>
    
asked by anonymous 27.06.2018 / 15:02

1 answer

1

Try copying the value of the string instead of passing the reference

 this.nomeProd = Object.assign('', formGroup.controls['nomeProduto'].value);
    
27.06.2018 / 15:51