Ionic 4 Popover implementation Error: No component factory found for ProfileComponent
Ionic 4 Popover implementation Error: No component factory found for ProfileComponent
我正在尝试在 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 {}
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();
}
如果您从 Page.ts 创建您的组件,您应该在 PageModule 中将您的组件声明为入口组件:
declarations: [
...,
ProfileComponent,
],
entryComponents: [ProfileComponent]
[2020 年 6 月 11 日更新]
使用 Angular 9,将不再需要 entryComponents
。有关详细信息,请参阅 this link
我正在尝试在 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 {}
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();
}
如果您从 Page.ts 创建您的组件,您应该在 PageModule 中将您的组件声明为入口组件:
declarations: [
...,
ProfileComponent,
],
entryComponents: [ProfileComponent]
[2020 年 6 月 11 日更新]
使用 Angular 9,将不再需要 entryComponents
。有关详细信息,请参阅 this link