I want to create a dropdown list with searchbar with the list containing data from a REST API. Initially in the searchbar I created I could just select the item but couldn't display that in the searchbar. I want the selected item to be displayed in the searchbar.How can I display that selected item.
I need to display it because I'm building a cascading dropdown list where the input of the first list is served to the second list.
I'll be thankful if someone can provide me the code by putting mind that the data is being rendered from a REST API using POST method.This is my function which gets called in the html page. userData is an array of type object since I need to get JSON data.I get an error saying property toLowerCase cannot exist on of the type Object.
loadusers(ev:any){
this.UserService.post('search/getusers',{}).subscribe(resp=>{
this.userData = resp.data;
console.log(this.userData);
},
err=>{console.log(err);},
()=>{});
let val = ev.target.value;
// if the value is an empty string don't filter the items
if (val && val.trim() != '') {
this.userData = this.userData.filter((item) => {
return (item.toLowerCase().indexOf(val.toLowerCase()) > -1);
})
}
}
This is the HTML file where I'm trying to display the data along with a searchabar.I also don't know what to include in the isChanged function.
<ion-searchbar [(ngModel)]="mySearchInput" (ionInput)="loadusers($event)"></ion-searchbar>
<ion-content >
<ion-list radio-group [(ngModel)]="selectedValue">
<ion-item class="border" *ngFor="let val of userData">
<ion-label>{{val.name}}</ion-label>
<ion-radio class="resolvedState" value="{{val.name}}" (ionSelect)="isChanged(val)"></ion-radio>
</ion-item>
</ion-list>
What is the best practise to create a searchbar with these features ?