0
I am crud using Angular and am having trouble updating the values of my API objects. Basically, when I run the update method it updates in the API, but the field that has been updated, instead of receiving the updated content, updates itself as if it were an empty string. I debugged and I am receiving the value of the field I want to return inside my variable and I pass this value as parameter inside my method. I need to know what’s wrong and how to fix it. Thank you!
Service used in the method:
atualizaProdutos(id: number, produto: Produtos): Observable<Produtos>{
const url = `${environment.produtosApiUrl}/produtos/${id}`;
return this.http.put<Produtos>(url, produto.descricao);
}
Method:
atualizaProduto(id: number, descricao){
console.log(descricao);
this.produtosServices.atualizaProdutos(id, descricao)
.subscribe(() => {alert('Descrição Atualizada!')},
() => {alert('Falha ao Editar a Descrição!')});
debugger
}
Knob:
<button type="button" class="btn btn-primary" (click)="atualizaProduto(id, descricao)">Salvar Edição</button>
It was not clear your question, where do you leave the field blank, in the bank? If it is in the bank the problem is not in the front but in the api.
– LeAndrade
After clicking the button, when I reload the page to see the list, the field that previously had something appears blank. Example, before had description: hamburger after I upgrade the field is blank.
– Bruno Eduardo Rosselli
You have a POST method that does the insertion into the database, but, then you have to have a GET-pair method when the page is loaded go into the database and bring the data into the field.
– LeAndrade
Yes, but then it would only update the content that exists in the API. The problem is that when I update, the content that goes to the API does not go and the object’s description field looks like an empty string and then when I update the page the object appears, but with the Description field empty. It does not insert the updated content into the API.
– Bruno Eduardo Rosselli