【发布时间】:2017-12-31 02:12:50
【问题描述】:
我有一个标签组:
<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>
当用户单击第二个选项卡(“工作室”)时,我需要检查他们是否可以访问它。如果他们这样做,很好,如果他们不这样做,我想显示一个 toast 通知并加载第一个标签。
我该怎么做?
我认为return false 足以满足studioCheck(),但事实并非如此。
打字稿:
studioCheck() {
console.log('Studio visited');
// Grab studio selected level
this.storage.get('studio_level').then((val) => {
console.log('Storage queried');
if(val) {
console.log('Level ID: ', val);
return true;
} else {
// No level selected
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;
}
});
}
我认为ionSelect 可能不会等待异步的storage.get 调用,所以我只是在函数顶部做了一个return false;,但效果相同。
有什么想法吗?
【问题讨论】:
标签: angular typescript ionic-framework ionic2