So I have the following situation
- I have created an angular library
ng generate library my-lib - I have added a simple component using
Ng generate component .lib/testwhich creates a standalone component like so
import { Component } from '@angular/core'; @Component({ selector: 'lib-test', standalone: true, imports: [], templateUrl: './test.component.html', styleUrl: './test.component.css' }) export class TestComponent { }
- I then pack up my application by running
ng buildthencd ../../dist/my-lib && npm pack - I go to my main application and run
npm install {pointTofolder}/dist/my-lib/my-lib-0.0.1.tgz - I go to use in my application and I get the following error
'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
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)
If your component is not a Standalone component, you can do the same thing but import it through a module
And in this case
CommonUiModulelooks like the following