Reputation: 3199
I have an Angular Workspace created with three projects. As well as I have just created a Library that I would like to have reusable modules inside.
Typically for the projects (applications and library) I run the following to generate a module or component:
ng g c component componentName --project=UserPortal
ng g c component componentName --project=myLibrary
However now I need to add components to the modules inside them:
For example the Library: projects myLibrary src lib navigation-module Add Component here
For Application Project Module: projects UserPortal src app userModule Add Component Here
I was able to create a module inside the Library project from the Workspace by running:
ng generate module navigation-module --project=myLibrary
Currently I have to go through command line down to that directory just to create a component. But I have a feeling I can do this from the Workspace like all the other commands. This would be most beneficial instead of either having to command lines up or going back and forth between directories.
Quick overview:
Upvotes: 11
Views: 13947
Reputation: 1316
You can pass your custom directory path along with ng
command.
ng g c myfolder\mycomponent
But there are chances that you miss spell the path and either new folder gets created or target directory changes. For this reason dryRun
is very helpful. It displays an output of how the changes is going to be affected.
After verifying the result you can run the same command without -d
to make the changes.
--dryRun=true|false
When true, runs through and reports activity without writing out results.
Default: false
Aliases: -d
Official Doc :- https://angular.io/cli/generate
Upvotes: 0
Reputation: 1402
You can create components for feature modules by providing the correct path. In your case
ng g c navigation-module/test-component --project=myLibrary
should do the trick.
Upvotes: 21