代码之家  ›  专栏  ›  技术社区  ›  th1rdey3

即使添加到入口组件后,也找不到NGX引导模式组件

  •  1
  • th1rdey3  · 技术社区  · 7 年前

    最近,我将一个ASP.NET Core2.0 Angular应用程序转换为ASP.NET Core2.1(稍后使用 angular/cli 应用程序)。在以前的版本中,我有一些用NGX引导构建的模态组件,它们工作正常。但是在转换之后,这些组件停止工作并开始抛出这个错误-

    未找到组件的组件工厂。是否将其添加到@ngmodule.entrycomponents?

    我在app.module.ts文件中添加了以下内容-

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

    在我的 MySubModule -

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

    即使我已经定义了入口组件,它还是抛出了这个错误。有人能提出任何解决方案吗?

    2 回复  |  直到 7 年前
        1
  •  2
  •   Lia    7 年前

    您在mymodalcomponent中使用model,并使用mysubmodule作为模块,因此应将import modal module添加到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

        2
  •  1
  •   th1rdey3    7 年前

    这实际上是个愚蠢的问题。我只是在看我的代码,但问题是由 ClientApp/dist 目录。因此,应用程序正在提取这些文件,而不是提取 ng serve 文件夹。所以,我对我的文件所做的任何更改都不会被接受。从dist文件夹中删除所有内容修复了该问题。