I'm developing an angled and php application and I'm running it all on localhost. on my front end I have a function that retrieves my information and displays. each line in the list has a button called delete to be able to delete this item, when I click on delete I get the id of the item and send a delete request to my server. I follow this along with the postman and it is possible to visualize that it really deletes all the files, but in my angular the item is still there, even though I remove it from the list when I try to retrieve the list using the method get the deleted item back but in the postman does not return.
Category.service.ts
get(page, descricao) {
page = 'all';
return this.http.get(Auth.url + this.nameClass + `?page=${page}&desc=${descricao}`, { headers: { 'token': Auth.token } });
}
delete(id) {
console.log(Auth.url + this.nameClass + "/" + id);
this.http
.delete(Auth.url + this.nameClass + "/" + id, { headers: { 'token': Auth.token } })
.subscribe(dados => alert('Ok'), (error: any) => alert('erro'));
}
When I use a function to delete the alert ('ok'), since my server returns true because it deleted perfectly
CategoryList.Component.ts
items: any;
ngOnInit() {
this.getList();
}
excluir(desc, id) {
if (confirm("Do you want to delete the category " + desc + " ?")) {
let index = this.getIndex(id);
if (index == -1)
alert('Error');
else {
let result = this.categoriaService.delete(id);
this.items.splice(index, 1);
}
}
}
getIndex(id) {
for (let i = 0; i < this.items.length; i++)
if (this.items[i].id == id)
return i;
return -1;
}
getList(page: number = 1) {
this.categoriaService.get(page, this.pesquisarValue)
.subscribe(dados => this.exibeLista(dados), (error: any) => console.log(error));
}
exibeLista(dados) {
this.items = null;
if (dados.result.count == 0) // Quantidade de itens retornados da consulta
this.pages = null;
else {
if (dados.result.paginas == 0) // Quantidade de paginas
this.pages = null;
else {
this.totalPages = dados.result.paginas;
this.loadPages();
}
this.items = dados.result.item;
}
I use the this.items.splice (index, 1) function; and removes the deleted item from my array of items, so far so good. when I leave this page and come back, the item is there again, even though it is not in postman. I am using the extension in the chrome of allow-control-allow-origin will this cause any problems? Is this my list in some cache? how can I delete data that has been deleted