gpt4 book ai didi

angular - 错误 : No Component Factory Found. 是否添加到@NgModule.entryComponents?

转载 作者:太空狗 更新时间:2023-10-29 17:18:14 24 4
gpt4 key购买 nike

我想在我的主页上创建一个弹出窗口。所以我创建了以下函数..

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)

我很困惑为什么要将它添加到入口组件中?

最佳答案

您需要将动态创建的组件添加到您的@NgModule 中的入口组件

@NgModule({
...
declarations: [
...
Name of your component,
],
entryComponents: [
...
Name of your component,
]
})

注意:在某些情况下,延迟加载模块下的入口组件将无法工作,作为一种解决方法,将它们放在您的 app.module(root)中

关于angular - 错误 : No Component Factory Found. 是否添加到@NgModule.entryComponents?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47442222/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com