I'm starting to use angular-cli and I've already read a lot to find an answer about what I want to do...no success, so I came here.
Is there a way to create a component to a new module?
e.g.: ng g module newModule
ng g component newComponent
(how to add this component to newModule??)
because the angular-cli default behavior is to put all new components inside app.module
. I would like to choose where my component will be, so that I can create separated modules and won't have all my components inside app.module
. It is possible to do that using angular-cli or do I have to do this manually?
First run
ng g module newModule
. Then runng g component newModule/newModule --flat
You can try below command, which describes the,
Then your command will be like:
1.- Create your feature module as usual.
2.- You can specify the ROOT PATH of your project in --module ( only in --module, (/) root points to your PROJECT ROOT and IS NOT THE SYSTEM ROOT!!!)
Real Example:
Output:
Tested with Angular CLI: 9.1.4
Not sure if maybe Alexander Ciesielski's answer was correct at the time of writing, but I can verify that this no longer works. It doesn't matter which directory in the project you run the Angular CLI. If you type
it will generate a component and import it into the app.module.ts file
The only way you can use CLI to automatically import it into another module is by specifying
where moduleName is a module you've already defined in your project. If the moduleName doesn't exist, it'll put the component in moduleName/newComponent directory but still import it into app.module
Use this simple command:
users
: Your module name.userlist
: Your component name.I created component based child module with specific Root Folder
That cli command below i specified,please check out
Repair is Root Folder of our child module