I’m sorry, the error was in the function that calls the POST service, in it I was mistakenly changing the value of productos, I just deleted that line and everything started working fine
Solution 1 :
Problem :
I have a list in Angularjs that is automatically filled with *ngFor, but when I make use of a POST service, said list stops working and only shows the default option
<select id="descripSel" (change)="selectDescrip()" >
<option >Selecciona un producto</option>
<option *ngFor="let item of productos | filter : txtdescrip : 'descripcion'" value="{{item.descripcion}}">{{item.descripcion}} </option>
</select>
The function in the component.ts is this one, it uses a POST service and saves some values, but then my list stops working:
selectDescrip() {
this.seldescrip=<HTMLSelectElement>document.getElementById("descripSel");
this.descripcion=this.seldescrip.value;
var j_number=null;
for(var i=0;i<this.productos.length;i++) {
if(this.productos[i]["descripcion"]==this.descripcion) {
j=i;
}
}
console.log(j)
this._serviceProductos.postDescrip(this.productos[j])
.then(response=>{
if(response["producto"]==null||response==null){
alert("No se encontró ningún producto con la descripción especificada, favor de validar la descripción")
} else {
this.productos=response.productos;
this.resprod=response["producto"];
this.precios=[
this.resprod["precio_contado"],
this.resprod["precPG_99"],
this.resprod["precPG100_399"],
this.resprod["precPG400"],
this.resprod["precArq_99"],
this.resprod["precArq100_399"],
this.resprod["precArq400"],
this.resprod["precSubD_A"],
this.resprod["precSubD_B"],
this.resprod["precSubD_CD"]
]
this.descripcion=this.resprod["descripcion"];
this.sku=this.resprod["sku"];
this.actualizarFoto(this.resprod["foto"]);
console.log(this.resprod)
}
})
.catch(error=>{
console.log(error);
})
}
Comments
Comment posted by Alex – Tin Le
what do you mean by stop working? the select shows no options as soon as you select 1 option?
Comment posted by Elías García Zarazúa
Yes, when I select any option it sends the value to the function and then it only shows the default option: “Selecciona un producto”
Comment posted by Alex – Tin Le
Do you got any exception in console? Will it work if your selectDescrip() is empty?