Ionic 3懒惰加载在选项卡上

时间:2017-11-13 19:53:29

标签: angular typescript ionic-framework ionic2 ionic3

我想使用延迟加载为项目添加一个新选项卡。

我正在使用let装饰器作为选项卡的根页面。

我的新页面:

@IonicPage

并尝试在我的标签中使用它:

// module
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { UsersPage } from './users';

@NgModule({
  declarations: [
    UsersPage,
  ],
  imports: [
    IonicPageModule.forChild(UsersPage),
  ],
})
export class UsersPageModule {}

// page
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';

@IonicPage()
@Component({
  selector: 'page-users',
  templateUrl: 'users.html',
})
export class UsersPage {

  constructor(public navCtrl: NavController, public navParams: NavParams) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad UsersPage');
  }

}

但是我收到以下错误:

// tabs.ts
export class TabsPage {
  @ViewChild(Tabs) tabs: Tabs;
  @ViewChild('findTab') findTab: ElementRef;

  // this tells the tabs component which Pages
  // should be each tab's root Page
  tab1Root: any = HomePage;
  tab2Root: any = FindPage;
  usersPage: any = "UsersPageModule";
  tab4Root: any = ChatsPage;

  findTabParams: any = {};
  subscriptions: any[] = [];
  totalUnreadMessages: FirebaseObjectObservable<any>;
  unread: boolean;
  anyUnread: boolean;
  ...

// tabs.html
<ion-tabs #tabs>
  <ion-tab [root]="tab1Root" tabIcon="home"></ion-tab>
  <ion-tab #findTab [root]="tab2Root" [rootParams]="findTabParams" tabIcon="calendar"></ion-tab>
  <ion-tab [root]="usersPage" tabIcon="person"></ion-tab>
  <ion-tab [root]="tab4Root" tabIcon="chatbubbles" [tabBadge]="unread?1:null" [tabsHideOnSubPages]=true></ion-tab>
</ion-tabs>

即使重新运行Uncaught (in promise): invalid link: UsersPageModule

1 个答案:

答案 0 :(得分:0)

您不应该使用页面的模块,而是使用页面本身:

  // ...

  // this tells the tabs component which Pages
  // should be each tab's root Page
  tab1Root: any = HomePage;
  tab2Root: any = FindPage;
  usersPage: any = 'UsersPage'; // <--- here! :)
  tab4Root: any = ChatsPage;

  // ...