Search with Ionic 3

0

I need to search ionic 3 but I can not.

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



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

The data is coming from an API.

    
asked by anonymous 01.06.2017 / 20:04

1 answer

0

Try to build on what I did :) That works, here I'm pulling 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);

  }
    
11.01.2018 / 04:53