ionic 3, lazy-loading tabs components

2019-02-12 18:18发布

I'm trying to create a ionic 3 tabs app with lazy loading without importing the components .

in my app.component.ts

 rootPage:string = "Tabs";

in tabs.html

<ion-tabs>
<ion-tab [root]="Favorites" tabTitle="fav" tabIcon="star"></ion-tab>
<ion-tab [root]="libaray" tabTitle="Library" tabIcon="book"></ion-tab>
</ion-tabs>

in Favorites.module.ts

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { Favorites } from './favorites';

@NgModule({
  declarations: [
    Favorites,
  ],
  imports: [
    IonicPageModule.forChild(Favorites),
  ],
  exports: [
    Favorites
  ]
})
export class FavoritesModule {}

so far , the tabs page loads successfully but no view (blank page) . i think the problem that i'm using [root] attribute with lazy loading ! how to fix that ?

Thanks

2条回答
Fickle 薄情
2楼-- · 2019-02-12 19:11

Ensure at Tabs.html you include [root]="FavoritesRoot" as indicated below

<ion-tabs>
<ion-tab [root]="FavoritesRoot" tabTitle="fav" tabIcon="star"></ion-tab>
<ion-tab [root]="libarayRoot" tabTitle="Library" tabIcon="book"></ion-tab>
</ion-tabs>
查看更多
We Are One
3楼-- · 2019-02-12 19:17

Check here.

<ion-tab [root]="Favorites" tabTitle="fav" tabIcon="star"></ion-tab>
<ion-tab [root]="libaray" tabTitle="Library" tabIcon="book"></ion-tab>

Here libaray and Favorites need to be variables of the component.

In your component try setting string equivalent of the ionic page to the variables in Tabs.ts:

export class Tabs{
 Favorites:any='Favorites';
 libaray:any = 'libaray'; //assuming you tried to give the page class name to `root`.
}

Note: Be sure not to import your lazy loaded pages anywhere other than within the page module.

查看更多
登录 后发表回答