I have a group of tabs:
<ion-tabs>
<ion-tab [root]="tab1Root" tabTitle="Programmes" tabIcon="icon-programmes"></ion-tab>
<ion-tab [root]="tab2Root" (ionSelect)="studioCheck()" tabTitle="Studio" tabIcon="icon-studio"></ion-tab>
<ion-tab [root]="tab3Root" tabTitle="Library" tabIcon="icon-library"></ion-tab>
<ion-tab [root]="tab4Root" tabTitle="Profile" tabIcon="icon-profile"></ion-tab>
</ion-tabs>
When the user clicks on the second tab ("Studio"), I need to check if they have access to it yet. If they do, great if they don’t, I want to show a notification about the toast and load the first tab.
How can i do this?
I thought that’s return falseenough for studioCheck(), but it’s not.
Typescript:
studioCheck() {
console.log('Studio visited');
this.storage.get('studio_level').then((val) => {
console.log('Storage queried');
if(val) {
console.log('Level ID: ', val);
return true;
} else {
let toast = this.toastCtrl.create({
message: 'Please choose a programme in order to use the Studio',
duration: 3000,
position: 'top'
});
toast.present();
this.navCtrl.parent.select(0);
return false;
}
});
}
I thought that it might ionSelectnot wait for an asynchronous call storage.get, so I just did return false;at the top of the function, but it does the same.
Any ideas?
source
share