如何在我的离子2 sidemenu中添加注销选项卡?如果您已登录,则在仪表板页面上。现在,我有一个菜单项"注销",它只会将我带到主页。这是所有菜单项的App.component.ts中的页面数组:
this.pages = [
{title: 'Dashboard', component: DashboardPage},
...
{title: 'Logout', component: HomePage}
];
,但是现在我需要在注销后面添加逻辑,而不仅仅是页面开关。当我单击"注销"选项卡而不是仅转到主页时,是否可以调用函数logout()?
编辑:
这是开放式函数:
openPage(page) {
this.nav.setRoot(page.component);
}
您可以将组件设置为登录选项中的null
中的nullthis.pages = [
{title: 'Dashboard', component: DashboardPage},
...
{title: 'Logout', component: null}
];
,然后在您的方法中:
openPage(page) {
if(page.component) {
this.nav.setRoot(page.component);
} else {
// Since the component is null, this is the logout option
// ...
// logout logic
// ...
// redirect to home
this.nav.setRoot(HomePage);
}
}
我知道这已经回答,但是任何人都可以觉得这很有用。
this.pages = [
{title: 'Dashboard', component: DashboardPage},
{title: 'Logout', component: HomePage},
{title: 'Share', component: ''}
];
openPage(page) {
switch (true) {
case ((page.title == 'Logout')): {
console.log('Clicked Logout button');
// this.logout(); // call logout logic method
}
break;
case ((page.title == 'Share')): {
console.log('Clicked Share button');
// this.share(); call share logic method
}
break;
default: {
this.nav.setRoot(page.component);
}
break;
}
}