Home > Software engineering >  Angular does not render custom component
Angular does not render custom component

Time:12-18

I have an html file which looks like this:

  <div  >
    <div >
      <custom-button
        name="btnradio"
        id="0_0"
        text="0 - 0"
      ></custom-button>
  </div>
  </div>

THis component looks and works in other places without any problem but here on this component I am getting the following error:

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.

But the module of the library which has the custom-button component exports it and looks like this:

@NgModule({
  imports: [
    CommonModule,

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

And my module where I want to use this imports this module:

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

Can anyone tell me what the error is? I can not find it

CodePudding user response:

When working with library modules, the api is defined in the index.ts on the root or the library (my-lib/src/index.ts)

So, besides exporting it within the module like you already did, you should export whatever you want to expose to the lib consumers in the index.ts

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

CodePudding user response:

I found the problem. It was storybook, due to me only starting my component with storybook components from other modules were none existing, which makes sense. So starting the application normaly with npm showed me it worked as it should.

  • Related