How to get index of selected value in "ionic-selectable"

As [items] is containing an array of values that i believe have indexes those i want to retrieve so i can further use them. this is my html code for it. please help me find the index of selected value

 <ionic-selectable

        formControlName="broker"

        name="broker"

        [items]="brokersListNames"

        [canSearch]="true"

        (onChange)="brokerValue($event)">

      </ionic-selectable>

What is ionic-selectable, that doesn’t sound like a official Ionic Component

i read about it from here. Actually i was in need of an ion-select with search bar but couldn’t find something like that so i used it. also i’m new to ionic so i thought someone could guide me well.

If you need help with an external library, you should normally ask and search for help in their repository.

A ion-select with an integrated Searchbar doesn’t exist, that’s correct, but you can also create a own by using a Popover

okay that sounds great. so if you could help me make such ion-select than that would be really helpful.

If there is already a component like ionic-selectable i would first continue using this as a beginner.

So at the end of the day you have an array and an item out of this and you want to have the index of this?

Use indexOf:

this.brokersListNames.indexOf(item)

well, i tried it this way:

brokerValue(item){

    this.test = this.brokersListNames.indexOf(item)

    console.log("test", this.test);

}

but it’s not giving correct index. what i’m doing wrong can you please tell?

If you would have a look at the GitHub Repo you would see that the “$event” is not the item itself. What is the output of console.log(item);? It should hava a value key, so you have to use item.value in the indexOf function

1 Like

now it is working perfectly fine. thank you.