Create component as a library in Angular Nrwl Nx

Viewed 5846

I'm very new in Angular Nx. I have to create reusable Angular component and store it as a Library according to Nx workspace structure. I can't find appropriate command. I tried create library using:

 ng generate lib mylib

It creates library as expected, but I want to store there component which can be used later in my apps.

1 Answers

These are two separate actions - you have to generate a lib in order to create the lib in the workspace (and optionally have a module and import it into another module).

After you do this you can create a component inside this lib.

ng generate component mycomponent --project=mylib --module=mylib.module.ts --export

Note that we are exporting it to use it elsewhere.

Related