簡體   English   中英

Angular 不渲染自定義組件

[英]Angular does not render custom component

我有一個看起來像這樣的 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
    ],
})

誰能告訴我錯誤是什么? 我找不到它了

使用庫模塊時,api 在根目錄或庫 (my-lib/src/index.ts) 的 index.ts 中定義

所以,除了像你已經做的那樣在模塊中導出它之外,你應該導出你想要暴露給 index.ts 中的 lib 消費者的任何東西

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

我發現了問題。 這是故事書,因為我只是從其他模塊的故事書組件開始我的組件是不存在的,這是有道理的。 所以用 npm 正常啟動應用程序向我展示了它應該正常工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM