Hi, i have other searchbars in my project but just one is not working, here is my code (whose is similar to other searchbars):
PAGE.HTML:
<ion-content padding class="page-medico-formulario"> <ion-searchbar (ionInput)="getItems($event)" placeholder="Buscar..."></ion-searchbar> <ion-list *ngIf="estadoTrue"> <ion-item *ngFor="let e of estadosFiltro" id="{{e.id}}" (click)="setarEstado($event, e.id)"> {{ e.nome }} </ion-item> </ion-list> <ion-content>
PAGE.TS:
estados: any[];
estadosFiltro: any[] = [];
estadoTrue: boolean
initializeItems() { this.estadosFiltro = this.estados; }
constructor(public navCtrl: NavController, public loadCtrl: LoadingController, public formb: FormBuilder, af: AngularFire, public storage: Storage, public alerts: AlertController, public cid: CidadesProvider) {
this.estados = cid.getCidades();
this.initializeItems();
this.estadoTrue = false;
this.estadoTrue = true;
}
// Reset items back to all of the items
this.initializeItems();
// set val to the value of the searchbar
let val = ev.target.value;
// if the value is an empty string don't filter the items
if (val && val.trim() != '') {
this.estadosFiltro = this.estadosFiltro.filter((item) => {
return (item.toLowerCase().indexOf(val.toLowerCase()) > -1);
})
}
}
setarEstado($event, id) {
console.log(id);
}
}
This is basically my page (i’ve taken off code that doesn’t matter for the problem and that is working fine).
I’ve tryed the following:
- Using (keyup) instead of (ionInput).
- Taking it off the form it was placed (it was on a formGroup).
- Removing the *ngIf.
- Using a ngModel to pass the parameter of the typed word/letters.
- Creating a method in my provider that pass me the data that is filling my list.
Does someone know what i’m doing wrong?
UPDATE:
Here is the data model of the JSON i’m working with, don’t know if i cam be a problem:
[
{
"id": 0,
"sigla": "AC",
"nome": "Acre",
"cidades": [
"Acrelândia",
"Assis Brasil",
...
]
}, ...
]