ngx-bootstrap Modal Component即使添加到条目组件后也找不到

时间:2018-07-29 05:41:34

标签: angular angular6 ngx-bootstrap ngx-bootstrap-modal

最近,我已将ASP.NET Core 2.0 Angular应用程序转换为ASP.NET Core 2.1(后一种使用angular/cli应用程序)。在以前的版本中,我有一些使用ngx-bootstrap构建的模态组件可以正常工作。但是在转换之后,这些组件停止工作并开始引发此错误-

  

找不到{component}的组件工厂。您是否将其添加到@ NgModule.entryComponents?

我已将以下内容添加到我的app.module.ts文件中-

@NgModule({
    imports: [
        ModalModule.forRoot(),
        MySubModule
    ],
    entryComponents: [
        MyModalComponent
    ]
})

在我的MySubModule中-

@NgModule({
    declarations: [
        MyModalComponent
    ],
    imports: [
        ModalModule.forRoot()
    ]
    exports: [
        MyModalComponent
    ]
})

即使我已经定义了输入组件,也会引发此错误。谁能提出任何解决方案?

2 个答案:

答案 0 :(得分:2)

您在MyModalComponent中使用模态,并使用MySubModule作为模块,因此您应将import ModalModule添加到MySubModule并在app.module.ts中声明MySubModule。

在MySubModule中:

import { ModalModule } from 'ngx-bootstrap/modal';

@NgModule({
    declarations: [
        MyModalComponent
    ],
    imports: [
        ModalModule.forRoot()
    ]
    exports: [
        MyModalComponent
    ]
})
export class MySubModule { }

在您的app.module.ts中:

@NgModule({
    imports: [
        MySubModule
    ]
})

export class AppModule { }

,最好使用ngbootstrap modal

答案 1 :(得分:1)

这实际上是一个愚蠢的问题。我只查看代码,但是问题是由ClientApp/dist目录中的某些文件引起的。因此,应用程序将提取这些文件,而不是提取ng serve文件。因此,我对文件所做的任何更改都不会被提取。从dist文件夹删除所有内容即可解决此问题。