How can I open the ‘Select’ component from my TypeScript code, and then fill that component with JSON from this.data. I’ve had a look at the documentation and seen the open() instance member, but I don’t know how to call it.
I’ve tried this: let multipleStudentSelect = this.select.open(); but how do I link this to the ion-select in my code.
<ion-select [(ngModel)]="multipleStudents">
<ion-option *ngFor="x of data.Students" [value]="x.Ref">{{x.Name}}</ion-option>
</ion-select>
Had the same issue, i want to open the ion-select dynamically if the current logged in user has more than one site that he can access, as you pointed out doc isnt that explanatory on open() but here is how you do it.
In your component aside from the template do it like this:
import { Select } from 'ionic-angular';
@Component({
templateUrl: '<your template here>'
})
export class SelectOpeningClass {
@ViewChild(Select) select: Select;
constructor() { do something }
ionViewWillEnter() { //or whatever method you want to use
this.select.open()
}
}
I think that timeouts like that should be avoided if at all possible (they behave unpredictably), and in this case it should be easy to do so. Don’t try to reference @ViewChild properties in the constructor; use ngAfterViewInit instead.
Thanks ramon, this helped me, there were one thing missing for me though, i navigated to another site when the ionChanged event was called, but if a user clicked the same option multiple times, nothing would happen except for the first time. It was not reset.
Adding select.value = undefined before the click event was enough, and made it function perfect for my use case, maybe someone else have the same need.