I tried adding ion-select-option and then tried to handle select all logic in the change event but change event doesn’t fire at all. seems it doesn’t support events
<ion-item>
<ion-label>Test</ion-label>
<ion-select [(ngModel)]="selectedValues" multiple="true">
<ion-select-option (ionChange)="selectAll()">Select All</ion-select-option>
<ion-select-option [value]="option" *ngFor="let option of items">{{option}}
</ion-select-option>
</ion-select>
</ion-item>
sample https://stackblitz.com/edit/ionic-5-angular-10-start-template-hure6j?file=src/app/tabs/tabs.page.html
Your code does not work because you placed the ionChange in the wrong place…
This is how you code should look like…
<ion-select [(ngModel)]="selectedValues" multiple="true" (ionChange)="selectAll()">
<ion-select-option [value]="all">Select All</ion-select-option>
<ion-select-option [value]="option" *ngFor="let option of items">{{option}}
</ion-select-option>
</ion-select>
redcort
September 25, 2020, 3:17pm
3
1 Like
Please adopt something along the lines of @redcort ’s solution. It is important to make “select all” not look like the rest of the options.
1 Like