Ionic select CompareWith

compareWith is not properly working for multiselect select. I not sure whether I’m using it properly or not . Kindly any one have knowledge in that help me. Thanks in advance

<ion-select multiple [compareWith]=“compareWithFn” name=“myLanguage” [(ngModel)]=“myLanguage”>
<ion-select-option *ngFor=“let l of languages” [value]=“l.id”>
{{ l.name }}

TS:
compareWith: (o1: any, o2: any) => boolean;

this.compareWith = this.compareWithFn;

compareWithFn=(o1, o2) =>{
return o1 === o2;
};

Can you rewrite this so neither the word any nor this appears anywhere in the relevant code? While I understand it may sound like a strange and silly request, I think it will shine some light on things.

TS:
declaration:
compareWith: (o1: any, o2: any) => boolean;

inside constructor:
this.compareWith = this.compareWithFn;

seperate function:
compareWithFn=(o1, o2) =>{
return o1 === o2;
};

That’s two anys and two thises, so not what I was looking for.

I’m sorry I could not get you. Please correct my code.
Or kindly let me know how to correct it.

1 Like