如何在ionic4中使用弹出框加载页面

时间:2019-07-28 19:37:39

标签: ionic4 lazyload

如何在ionic 4中加载(延迟加载)页面而不是弹出框的组件? 我这样尝试:

  async CreateContent(ev: any) {
    const popover = await this.popoverCtrl.create({
      component: 'ContentPopoverPage',
      event: ev,
      translucent: true
    });
    popover.onDidDismiss().then((res: any) => {
      if (res.data !== undefined && res.data != null) {
        const gallery: IGallery = res.data.contentData;
        this.galleryList.unshift(gallery);
      }
    });

    return await popover.present();
  });

,错误结果为:

  

错误错误:未捕获(承诺):错误:找不到组件工厂   用于ContentPopoverPage。您是否将其添加到@ NgModule.entryComponents?

1 个答案:

答案 0 :(得分:0)

我在content-popover.module.ts中有这样的路由:

const routes: Routes = [
  {
    path: '',
    component: ContentPopoverPage
  }
];

所以我将路径从''更改为app.routing.module中的内容

const routes: Routes = [
  {
    path: 'content-popover',
    component: ContentPopoverPage
  }
];

之后,我在Gallery.module中导入了ContentPopoverPageModule

@NgModule({
  imports: [
    ContentPopoverPageModule,
    CommonModule,
    ...

在我的gallery.ts文件中finlay:

  import { ContentPopoverPage } from '../content-popover/content-popover.page';

  async CreateContent() {
    const popover = await this.popoverCtrl.create({
      component: ContentPopoverPage
  });

    popover.onDidDismiss().then((data: any) => {
    });

    await popover.present();
 }