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

角度:在NgModule entryComponents数组中使用库中的组件时出现问题

  •  0
  • Wolf359  · 技术社区  · 5 年前

    我有一个 showcase模块

    库模块 有一个 和一个 .

    PopoverService公司 使用 作为Angular CDK ComponentPortal构造函数的第一个参数:

    :

    open(...) {
        new ComponentPortal(
                        PopoverComponent,
                        // ...
        )
    }
    

    Showcase模块 使用 PopoverService公司 PopoverComponent公司

    Lib模块 是这样的:

    @NgModule({
        declarations: [PopoverComponent],
        imports: [
            // ... other modules
            OverlayModule
        ],
        providers: [PopoverService],
        exports: [PopoverComponent]
    })
    export class MyLibModule { }
    

    公共api.ts 是这样的:

    export * from './lib/my-lib.module';
    

    以及

    import { PopoverComponent } from 'my-lib/lib/components/popover/popover.component';
    @NgModule({
      // ... other
      imports: [
        // other modules
        MyLibModule
      ],
      entryComponents: [PopoverComponent]
    })
    export class ShowcaseModule { }
    

    但是我在调用popoOverService.open()时遇到了这个错误:

    ./src/app/modules/showcase/showcase.module.ts
    Module not found: Error: Can't resolve 'my-lib/lib/components/popover/popover.component' in '........./src/app/modules/showcase'
    

    我做错什么了?

    0 回复  |  直到 5 年前
        1
  •  0
  •   Wolf359    5 年前

    entryComponents: [PopoverComponent]
    

    在库模块中,而不是在使用Showcase模块中。不过,我不会因为@MikeOne的宝贵建议而删除这个问题。