How can I change the path of component generation to current path in angular-cli?
Well, after some googling and reading the other answers, it will be helpful to have some explanations here. To generate a component in your project:
cd path/your-project
In the console (node-prompt or your IDE console) type:
ng generate component components/your-new-component-name
If you want to abbreviate:
ng g c components/your-new-component-name
You can create other angular components like: ng g directive ng g module ...
Source and more info: Angular Official Documentation
You should avoid: 'route-to-your-project': this will concatenate routes when you execute: ng g c 'route-to-your-project' and the console will show you an error because could not find the correct place to generate.
Example:
ng g c components/alerts/test3
CREATE src/app/components/alerts/test3/test3.component.html (20 bytes)
CREATE src/app/components/alerts/test3/test3.component.spec.ts (621 bytes)
CREATE src/app/components/alerts/test3/test3.component.ts (266 bytes)
CREATE src/app/components/alerts/test3/test3.component.scss (0 bytes)
UPDATE src/app/components/alerts/alerts.module.ts (5046 bytes)
I hope it will be helpful for you
Suppose you have structure src/app
and you wanna create a component header
living at src/app/components/
you can run ng g c components/header
, which will generate files at src/app/components/header
folder, like src/app/components/header/header.component.ts
src/app/components/header/header.component.html
etc.
ng g c 'path/to/component/componentName'
You should never have to leave your root directory when working with angular cli. If you wanted all your components to go into a subdirectory called my-component you would just do ng g c my-component/componentName
Note that g and c are valid shortforms for generate
and component
respectively.