Thanks to @PareshGami
But in ionic 4, if you want to display the list only if a button
is clicked and hide select
1.Import IonSelect
import { Component, ViewChild } from '@angular/core';
import { Platform, Events, IonSelect } from '@ionic/angular';
2.Inside class, add reference to select
and set showList
to true to hide select
. Also add setCountry()
to retrieve selected country.
@ViewChild('countryList') selectRef: IonSelect;
showList = true;
setCountry() {
console.log('New country');
}
3.In HTML, add select
element with hidden property
<ion-select placeholder="Country" #countryList [hidden]='showList' (ionChange)='setCountry()'>
<ion-select-option value="1">Egypt</ion-select-option>
<ion-select-option value="2">Kuwait</ion-select-option>
<ion-select-option value="3">UAE</ion-select-option>
<ion-select-option value="4">Qatar</ion-select-option>
<ion-select-option value="5">Bahrain</ion-select-option>
<ion-select-option value="6">Saudi Arabia</ion-select-option>
</ion-select>
<ion-label (click)='displayCountry()'>Change</ion-label>
So select
element is invisible and clicking Change
will display the country list to select.