我正在尝试在我的主页上创建一个弹出窗口。所以我创建了以下功能..
public presentPopover(myEvent) {
let popover = this.popoverCtrl.create(TestComponent);
popover.present({
ev: myEvent
});
}
在我的homepage.module.ts中我添加了testComponent作为条目组件。
import { TestModule } from './../../components/test/test.module';
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { HomePage } from './home';
import { TestComponent } from './../../components/test/test';
@NgModule({
declarations: [
HomePage,
],
imports: [
TestModule,
IonicPageModule.forChild(HomePage),
],
entryComponents: [
TestComponent,
]
})
但是当我点击弹出按钮时,我仍然会收到此错误。
ERROR Error: Uncaught (in promise): Error: No component factory found for TestComponent. Did you add it to @NgModule.entryComponents?
Error: No component factory found for TestComponent. Did you add it to @NgModule.entryComponents?
at noComponentFactoryError (core.js:3786)
at CodegenComponentFactoryResolver.resolveComponentFactory (core.js:3850)
at PopoverCmp._load (popover-component.js:41)
at PopoverCmp.ionViewPreLoad (popover-component.js:33)
我很困惑为什么要将其添加到条目组件?
答案 0 :(得分:9)
您需要将动态创建的组件添加到@NgModule
中的条目组件中@NgModule({
...
declarations: [
...
Name of your component,
],
entryComponents: [
...
Name of your component,
]
})
注意:在某些情况下,延迟加载模块下的条目组件将无法正常工作,因为解决方法将它们放入app.module(root)