网站搜索

angular - 这是使用 ionic3 的页面跳转


我设置了一个标签页,A、B、C。像这样:

tab1Root: any = HomePage;
tab2Root: any = AboutPage;
tab3Root: any = ContactPage;

当我从 PageB 跳转到一个新的 pageC 时,URL 变为:http://localhost:8102/#/about/shopping;当我重新加载购物页面时,我遇到了一个错误:

组件 AboutPage 不属于任何 NgModule,或者该模块没有被导入到你的模块中。我是新手,希望有人能帮助我;这是我的代码:

about.ts:

  import { Component } from '';
  import { IonicPage, NavController, NavParams } from 'ionic-angular';
  @ionicpage()
  @component({
   selector: 'page-about',
   templateUrl: 'about.html',
  })
  export class AboutPage {
  lists = Lists
  constructor(public navCtrl: NavController, public navParams: 
   NavParams) {}
  ionViewDidLoad() {}
  openPage(page){
    this.navCtrl.push(page)
   }
  }

about.module.ts

import { NgModule } from '';
import { IonicPageModule } from 'ionic-angular';
import { AboutPage } from './about';
@NgModule({
declarations: [
 AboutPage,
],
imports: [
 IonicPageModule.forChild(AboutPage),
],
})
export class AboutPageModule {}

答案#1

我从未使用过选项卡组件,但当我创建一个新页面并且没有将其添加到 entryComponents 部分时,也出现了同样的错误,如下所示:

import { NgModule } from '';
import { IonicPageModule } from 'ionic-angular';
import { AboutPage } from './about';
@NgModule({
declarations: [
     AboutPage,
],
imports: [
     IonicPageModule.forChild(AboutPage),
],
entryComponents: [
     AboutPage,
]
})

如果你在 EntryComponent 部分声明你的新页面,应该可以解决你遇到的问题:

AboutPage 不是任何 NgModule 的一部分,或者该模块尚未被导入到您的模块中

根据文档 EntryCompmonents:

定义在定义此组件时也应编译的组件。对于此处列出的每个组件,Angular 将创建一个 ComponentFactory 并将其存储在 ComponentFactoryResolver 中。