Search with Ionic 3

Asked

Viewed 265 times

1

I need to do a search on Ionic 3 but I’m not getting it.

 <ion-searchbar 
    [(ngModel)]="searchTerm"
    (ionInput)="filterItems()" 
    placeholder="Buscar Pedido" >
 </ion-searchbar>



 filterItems(){
    this.evento.loadPedido(this.searchTerm).subscribe(pedido => {
      this.pedido = pedido
    })
  }

Data is coming from an API.

1 answer

1

Try to base on what I did :) that works, here I am pulling from an API too and it’s working perfectly :)

.HTML

   <ion-searchbar placeholder="Pesquisar material..." (ionInput)="Buscar($event)"></ion-searchbar>

.TS

      buscarItems() {
    this.ListaDados = this.dados;
  }


  buscarLocais() {
    this.service.buscarTarefas().then(data => {
      this.dados = data;
      console.log(this.ListaDados);
    }).catch(error => {
      console.log(error);
    });
  }

  Buscar(event) {

    this.buscarItems();

    var q = event.srcElement.value;


    if (!q) {
      return;
    }

    this.ListaDados = this.ListaDados.filter((v) => {
      if (v.equipe && q) {
        if (v.equipe.toLowerCase().indexOf(q.toLowerCase()) > -1) {
          return true;
        }
        return this.buscarLocais();;
      }
    });
    console.log(q, this.ListaDados.length);

  }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.