-1

我想在用户登录后更改我的侧边菜单,以便显示名称及其侧边菜单。我认为这段代码是可以理解的。

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

2 回答 2

1

登录时在本地存储中设置令牌

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

希望这对你有帮助!

于 2017-09-21T05:22:55.693 回答
0

ionic 会议应用程序准确地展示了如何做到这一点,使用事件系统、本地令牌存储和带有页面的数组。也沿着 Jaydeep Kataria 的代码行。

使用 ionic 会议模板(当然是最新的 ionic 版本)开始一个新项目

问候,

汤姆

于 2017-09-21T11:39:29.407 回答