typescript Angular 不渲染自定义组件

lf3rwulv  于 2022-12-19  发布在  TypeScript
关注(0)|答案(2)|浏览(152)

我有一个html文件,看起来像这样:

<div  class="row">
    <div class="col-3">
      <custom-button
        name="btnradio"
        id="0_0"
        text="0 - 0"
      ></custom-button>
  </div>
  </div>

此组件在其他地方看起来和工作没有任何问题,但在此组件上,我得到以下错误:

NG0304: 'custom-button' is not a known element (used in the 'DailyTotalViewComponent' component template):
1. If 'custom-button' is an Angular component, then verify that it is a part of an @NgModule where this component is declared.
2. If 'custom-button' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.

但是库中包含自定义按钮组件的模块将其导出,如下所示:

@NgModule({
  imports: [
    CommonModule,

    RouterModule.forChild([
      /* {path: '', pathMatch: 'full', component: InsertYourComponentHere} */
    ]),
  ],
  declarations: [
    CustomButtonComponent
  ],
  exports: [CustomButtonComponent],
})

我想使用的模块导入了这个模块:

@NgModule({
    imports: [CommonModule, CustomButtonModule],
    declarations: [TableViewComponent
    ],
})

谁能告诉我错误在哪里?我找不到

ukxgm1gy

ukxgm1gy1#

使用库模块时,API在根目录或库(my-lib/src/index.ts)上的index.ts中定义
因此,除了像您已经做的那样在模块中导出它之外,您还应该导出您想要在index.ts中向lib使用者公开的任何内容

export * from './lib/my-lib.module';
//components
export * from './lib/some-component.component';
voj3qocg

voj3qocg2#

我发现了问题,是storybook,因为我只使用storybook组件启动我的组件,而其他模块的组件不存在,这是有道理的,所以使用npm启动应用程序显示它正常工作。

相关问题