【问题标题】:Ionic 4 Popover implementation Error: No component factory found for ProfileComponentIonic 4 Popover 实现错误:找不到 ProfileComponent 的组件工厂
【发布时间】:2019-08-10 07:22:57
【问题描述】:

我正在尝试在 ionic 4 中实现弹出框,它为我显示此错误,我为弹出框创建了一个独特的组件,并且正在页面上实现,所以我单击按钮来创建组件它给出了这个错误。

我正在使用延迟加载并将模块导入文件,我做错了什么?

ERROR Error: "Uncaught (in promise): Error: No component factory found for ProfileComponent. Did you add it to @NgModule.entryComponents?

弹出框模块

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { ProfileComponent } from './profile.component';

@NgModule({
  declarations: [ProfileComponent],
  imports: [
    CommonModule,
  ],
  entryComponents: [ProfileComponent],
})
export class ProfileModule { }

页面模块:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { Routes, RouterModule } from '@angular/router';
import { IonicModule } from '@ionic/angular';
import { ProfilePage } from './profile.page';
import { ValidationSummaryComponent } from '../../../components/validation-summary/validation-summary.component';
import { ProfileComponent } from '../../../components/popovers/profile/profile.component';
import { IonicSelectableModule } from 'ionic-selectable';

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

@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    IonicModule,
    ReactiveFormsModule,
    IonicSelectableModule,
    RouterModule.forChild(routes)
  ],
  declarations: [
    ProfileComponent,
    ProfilePage, 
    ValidationSummaryComponent, 
  ]
})
export class ProfilePageModule {}

创建popover的Page.ts方法:

import { ProfileComponent } from '../../../components/popovers/profile/profile.component';      
async openPopover(ev: any) {
        const popover = await this.popoverCtrl.create({
          component: ProfileComponent,
          event: ev,
          translucent: true
        });
        return await popover.present();
      }

【问题讨论】:

  • 能不能显示你导入PopoverModule和PageModule的地方
  • 您不需要配置文件模块。删除配置文件模块。您的页面模块看起来不错。
  • 我删除了配置文件模块,但错误仍然存​​在,我在 paginia 模块中弹出模块

标签: angular ionic-framework ionic4


【解决方案1】:

如果您从 Page.ts 创建组件,则应在 PageModule 中将您的组件声明为入口组件:

declarations: [
    ...,
    ProfileComponent,
],
entryComponents: [ProfileComponent]

[2020 年 6 月 11 日更新]

使用 Angular 9,将不再需要 entryComponents。请参阅this link 了解更多信息

【讨论】:

  • 谢谢我的朋友,为了运行,我在声明和入口组件处添加了组件。
  • 将我的 Popover 模块添加到 entryComponents 和声明列表中修复了它,谢谢!据说 Angular 9 entryComponents 将不再需要
猜你喜欢
  • 1970-01-01
  • 2019-03-02
  • 1970-01-01
  • 2020-07-01
  • 2019-07-10
  • 1970-01-01
  • 2012-03-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多