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 componen
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
ng g component newComponent
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
ng g component moduleName/newComponent
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
ng g c componentName --module=path-to-your-module-from-src-folder
example:
ng g c testComponent --module=/src/app/home/test-component/test-component.module
I am having the similar issues with multiple modules in application. A component can be created to any module so before creating a component we have to specify the name of the particular module.
'ng generate component newCompName --module= specify name of module'
First run ng g module newModule
. Then run ng g component newModule/newModule --flat
Go to module level/we can also be in the root level and type below commands
ng g component "path to your component"/NEW_COMPONENT_NAME -m "MODULE_NAME"
Example :
ng g component common/signup/payment-processing/OnlinePayment -m pre-login.module
For Angular v4 and Above, simply use:
ng g c componentName -m ModuleName