gpt4 book ai didi

angular - 错误 : Cannot determine the module for class

转载 作者:行者123 更新时间:2023-12-04 14:00:01 25 4
gpt4 key购买 nike

我在模块 A 中的一个组件 DialogComponent 中使用了一个指令 DialogHostDirective。它在模块 A 中工作正常的 ng-template 标签中使用。
该指令有一个 ViewContainerRef 用于在组件中插入模板。

我试图在我的模块 B 中使用 DialogComponent,它给了我一个错误:

错误中的错误:无法确定 C:/Users/jitdagar/Desktop/TDP/pwt-ui-common/src/app/components/dialog/dialog-host.directive.ts 中类 DialogHostDirective 的模块!将 DialogHostDirective 添加到 NgModule 以修复它。

模块 A 的 app.module

@NgModule({
declarations: [
AppComponent,
ExampleComponent,
DialogComponent,
DialogHostDirective,
OpenDialogContentComponent
],
imports: [
CommonModule,
FormsModule,
HttpModule,
ReactiveFormsModule,
BrowserModule,
AlloyModule,
MatDialogModule,
BrowserAnimationsModule
],
entryComponents: [
DialogComponent,
OpenDialogContentComponent
],
providers: [
DialogService
],
exports: [ExampleComponent, DialogComponent, DialogHostDirective],
bootstrap: [AppComponent]
})
export class PwtUiCommonModule {}

我没有在模块 B 中声明任何组件,因为它们已经在模块 A 中声明了。

最佳答案

您需要在 exports 中导出要在其他模块中使用的所有组件/指令模块声明数组。

我相信添加 exports: [ExampleComponent, DialogComponent, DialogHostDirective],并且可能其他必需的组件将解决您的问题。

请参阅 Angular 文档:How to declare feature modules

关于angular - 错误 : Cannot determine the module for class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50790142/

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