Angular, list is not update after deletion or insertion

0

I'm developing an application with angular and a api rest in PHP. I am doing a very simple CRUD, just to learn.

My problem is when I perform an insert / delete and soon afterwards I will retrieve a get with all the information. I have Category management, when I save this category via API it does not appear in my list of categories, it appears when I delete it, it is not excluded from my list of categories. but I'm using postman to be able to keep up with all those requests and they're made of facts.

I do not know, there seems to be something that prevents me from retrieving the updated list.

Example: I have 10 categories so I delete one and still continue displaying 10, even though I am accessing my api to retrieve the data again. If I reload after about 30 seconds the other category appears

Source code: category-list.component.list // The component that is used to view and delete

ngOnInit() {
    this.getList();
  }

  excluir(desc, id) {

    if (confirm("Deseja excluir a categoria " + desc + " ?")) {
      let index = this.getIndex(id);
      if (index == -1)
        alert('Não foi encontrado o index do código D:');
      else {
        let result = this.categoriaService.delete(id).
          subscribe(dados => { this.getList() },
            (error: any) => alert('erro'));
        //this.items = this.items.splice(index, 1);
        this.items = this.items.filter(item => item.id != id);
      }
    }
  }

  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._compiler.clearCache();
    this.categoriaService.get(page, this.pesquisarValue)
      .subscribe(dados => { console.log(dados); this.exibeLista(dados) }, (error: any) => console.log(error));
  }

  exibeLista(dados) {

    console.log('Total de Itens: ' + dados.result.count);
    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;
    }

    console.log("Quantidade: " + dados.result.count);
  }

Category.service

 insert(ObjJson) {
    /*console.log("Objeto");console.log(ObjJson);console.log("Caminho :"+Auth.url + this.nameClass);console.log("Token :"+Auth.token);*/
    if (ObjJson.id == null)
      return this.http.post(Auth.url + this.nameClass, ObjJson, { headers: { 'token': Auth.token } });
    else
      return this.http.put(Auth.url + this.nameClass + "/" + ObjJson.id, ObjJson, { headers: { 'token': Auth.token } });
  }

  get(page, descricao) {
    page='all';
    return this.http.get(Auth.url + this.nameClass + '?page=${page}&desc=${descricao}', { headers: { 'token': Auth.token } })
      .pipe(map(response => { return response })) // or try  'response.json()' instead of 'response' 
  }

  delete(id) {
    console.log(Auth.url + this.nameClass + "/" + id);
    return this.http
      .delete(Auth.url + this.nameClass + "/" + id, { headers: { 'token': Auth.token } });

  }

p>     
asked by anonymous 23.07.2018 / 23:52

0 answers