2017-03-10 1 views
2

이오 딕 2 사이드 메뉴에 로그 아웃 탭을 추가하려면 어떻게해야합니까? 로그인되어 있으면 DashboardPage에 있습니다. 지금은 홈페이지로 이동하는 메뉴 항목 "로그 아웃"이 있습니다.이오닉 2 - 사이드 메뉴의 로그 아웃 탭

this.pages = [ 
    {title: 'Dashboard', component: DashboardPage}, 
    ... 
    {title: 'Logout', component: HomePage} 
]; 

하지만 지금은 로그 아웃 뒤에 논리를 추가하고뿐만 아니라 페이지 전환 할 필요가 : 여기에 모든 메뉴 항목과 app.component.ts의 페이지의 배열입니다. HomePage로만 이동하는 대신 Logout 탭을 클릭하면 logout() 함수를 호출 할 수 있습니까?

편집 : 당신은 당신의 방법에 로그 아웃 옵션에 널 (null)로 다음

this.pages = [ 
    {title: 'Dashboard', component: DashboardPage}, 
    ... 
    {title: 'Logout', component: null} 
]; 

및 구성 요소를 설정할 수 있습니다

openPage(page) { 
    this.nav.setRoot(page.component); 
} 
+0

사이드 메뉴의 옵션을 선택한 경우 처리 할 방법을 추가 할 수 있습니까? – sebaferreras

+1

@sebaferreras done – Nono

+0

왜 'openPage'에서 페이지 제목을 확인하지 않는 것이 좋을까요? if (page.title ==='Logout ') {// 여기에서 로그 아웃 할 것} else {this.nav.setRoot (page. 구성 요소); }' – Und3rTow

답변

9

:

다음

가 openPage 기능입니다
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

Np, 도움이되었음을 기쁘게 생각합니다 @EdukondaluThaviti :) – sebaferreras

+0

하지만, 사이드 메뉴를 변경할 수 없습니다. 어떻게 사이드 메뉴를 새로 고칠 수 있습니까? –

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

    }