【问题标题】:Ionic 3 lazy-loading on a tab选项卡上的 Ionic 3 延迟加载
【发布时间】:2017-11-14 04:46:40
【问题描述】:

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

我正在将@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

即使重新运行ionic serve

【问题讨论】:

    标签: angular typescript ionic-framework ionic2 ionic3


    【解决方案1】:

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

      // ...
    
      // 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;
    
      // ...
    

    【讨论】:

    • 很高兴为您提供帮助:)
    猜你喜欢
    • 2017-09-19
    • 2017-11-20
    • 1970-01-01
    • 2011-03-17
    • 1970-01-01
    • 1970-01-01
    • 2018-02-01
    • 2014-08-16
    • 1970-01-01
    相关资源
    最近更新 更多