So I have the following situation
ng generate library my-lib
Ng generate component .lib/test
which creates a standalone component
like soimport { Component } from '@angular/core'; @Component({ selector: 'lib-test', standalone: true, imports: [], templateUrl: './test.component.html', styleUrl: './test.component.css' }) export class TestComponent { }
ng build
then cd ../../dist/my-lib && npm pack
npm install {pointTofolder}/dist/my-lib/my-lib-0.0.1.tgz
'lib-test' is not a known element:
- If 'lib-test' is an Angular component, then verify that it is part of this module.
- If 'lib-test' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
What am I missing / doing wrong? It's the most simple example of using a component in a library
I used these two links
And this lead me to the following:
Make sure the route is importing the module the Import's and Export's of that module
const routes: Routes = [
{
path: '',
component: MyComponent,
children: [
{
path: '',
loadChildren: () => import('./routes/my/my.module').then(m => m.MyModule)
},
]
}];
Then make sure that the component you want to load is in both the imports and the exports of the module you just loaded above (for standalone componets)
@NgModule({
imports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
RouterModule,
TestComponent
],
declarations: [
],
exports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
RouterModule,
TestComponent
]
})
If your component is not a Standalone component, you can do the same thing but import it through a module
imports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
RouterModule,
CommonUiModule
],
declarations: [
],
exports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
RouterModule,
CommonUiModule
]
And in this case CommonUiModule
looks like the following
@NgModule({
imports: [
],
declarations: [
TestComponent
],
exports: [
TestComponent
]