1
Good morning! I have a survey that puts the names of some products in a variable, but if I search another product, it subscribes the new product in the old, so:
Search for 1 product:
Search for 2° product:
As you can see, it replaces the value of the second of the first, and I even understand why, but I don’t know how to fix... Note: is just the name of the product.
Product Search Code:
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;
Página ts:
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) {
return this.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);
return this.nomeProd;
}
excluirLinha(codigo: any) {
for (let item of this.itens) {
if (item.codigoProduto == codigo) {
this.itens.splice(this.itens.indexOf(item), 1);
break;
}
}
}
HTML of the table:
<div class="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>
It has how to post the whole code and html tbm?
– Eduardo Vargas
@Eduardovargas I added the code of the table, I would need some more code?
– Bruno Miqueas
Put ts whole for example you are doing for in this items and don’t have it on ts.
– Eduardo Vargas
@Eduardovargas actually, the items won’t have much to do with what I’m trying to solve, they’ll just be passed by parameter, with no link to the product name, where is the problem
– Bruno Miqueas