2017-09-21 32 views
-1

我想在用戶登錄後更改我的sidemenu,以便顯示名稱及其旁邊菜單。我認爲這個代碼是可以理解的。Ionic 2 - 用戶登錄後的Sidemenu更改

rootPage: any = SlidesPage;  
    if(SlidesPage){ 
       this.pages = [ 
       { title: 'Welcome', component: SlidesPage }, 
       { title: 'Home', component: HomePage }, 
       { title: 'House & Lot', component: HousePage }, 
       { title: 'Condominium', component: CondoPage }, 
       { title: 'Apartment', component: ApartmentPage }, 
       { title: 'Hotel', component: HotelPage } 
       ]; 
      } else { 
       this.pages = [ 
       { title: 'Dashboard', component: SellerPage }, 
       { title: 'My Properties', component: SellerPage }, 
       { title: 'Properties', component: HomePage }, 
       { title: 'House & Lot', component: HousePage }, 
       { title: 'Condominium', component: CondoPage }, 
       { title: 'Apartment', component: ApartmentPage }, 
       { title: 'Hotel', component: HotelPage } 
       ]; 
      } 

回答

0

設置在localStorage的令牌當你登錄

this.storage.set('vAuthToken', vAuthToken);

然後在app.component.ts檢查它intializaApp()

initializeApp() { 
this.platform.ready().then(() => { 
    this.storage.get('vAuthToken').then((val) => { 
    if (val == null) { 
    this.menuCtrl.enable(false, 'authenticated'); 
    this.menuCtrl.enable(true, 'unauthenticated'); 
    } 
    else { 
    this.menuCtrl.enable(true, 'authenticated'); 
    this.menuCtrl.enable(false, 'unauthenticated'); 
    } 
    }); 
}); 
} 
this.authenticated = [ 
      { title: 'Welcome', component: SlidesPage }, 
      { title: 'Home', component: HomePage }, 
      { title: 'House & Lot', component: HousePage }, 
      { title: 'Condominium', component: CondoPage }, 
      { title: 'Apartment', component: ApartmentPage }, 
      { title: 'Hotel', component: HotelPage } 
      ]; 
      this.unauthenticated = [ 
      { title: 'Dashboard', component: SellerPage }, 
      { title: 'My Properties', component: SellerPage }, 
      { title: 'Properties', component: HomePage }, 
      { title: 'House & Lot', component: HousePage }, 
      { title: 'Condominium', component: CondoPage }, 
      { title: 'Apartment', component: ApartmentPage }, 
      { title: 'Hotel', component: HotelPage } 
      ]; 

希望這將幫助你!

+0

OK TY,我會嘗試這個時候我會在功能來工作現在我正在使用UI。 –

0

離子會議應用程序顯示瞭如何使用事件系統,本地令牌存儲和帶頁面的數組來完成此操作。也沿着Jaydeep Kataria的代碼。

剛開始一個新的項目,與離子會議模板(當然是最新的離子版本)

問候,

湯姆