I need to implement an ionic search which filters firebase data.
Here i getting data
dgetPlaces()
{
let ref = this.afDB.list('places').snapshotChanges()
.map(changes =>{
return changes.map(c=> ({key:c.payload.key,...c.payload.val()}));
});
return ref;
}
Then i Called on my home like
initializeItems()
{
this.places = this.dataProvider.dgetPlaces();
}
here is the html part for searching
<div class="contents">
<ion-searchbar [(ngModel)]="searchQuery" (ionInput)="setFilteredItems($event)"></ion-searchbar>
</div>
and finally here is the search function
setFilteredItems()
{
this.initializeItems();
this.places = this.places.filter((place)=>{
console.log(place.name)
return place.name.toLowerCase().indexOf(this.searchQuery.toLowerCase())>-1;
})
}
This works perfectly when i have normal array for places.But after adding firebase data the search is not working.It says
ERROR TypeError: Cannot read property 'toLowerCase' of undefined
How could I slove this???