Ionic 2 - Sidemenu中的Logout选项卡

时间:2017-03-10 11:48:03

标签: angular typescript ionic-framework ionic2 ionic3

如何在离子2侧面菜单中添加Logout Tab?如果您已登录,则表明您正在使用DashboardPage。现在我有一个菜单项" Logout"这只是带我到主页。这是app.component.ts中包含所有菜单项的pages数组:

[root@bmcapp ~]#systemctl daemon-reload


[root@bmcapp ~]#systemctl restart docker
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.`                                                                                   

但现在我需要在注销后面添加逻辑,而不仅仅是页面切换。当我点击Logout选项卡而不是仅转到HomePage时,是否可以调用函数logout()?

编辑:

这是openPage函数:

[root@bm ~]# docker info
Containers: 113
 Running: 29
 Paused: 0
 Stopped: 84
Images: 50
Server Version: 1.13.1
Storage Driver: overlay2
Kernel Version: 4.1.12-61.1.28.el7uek.x86_64
Operating System: Oracle Linux Server 7.3
OSType: linux
Architecture: x86_64
CPUs: 4

2 个答案:

答案 0 :(得分:10)

您可以在注销选项

中将组件设置为null
this.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);
    }
}

答案 1 :(得分:0)

我知道这已经得到了解答,但是任何人都可以发现这很有用。

    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;
      }

    }