2

Am having this issue, where when I generate components with Angular CLI instead of generating them in the same folder I have CD in it generate them in the App folder. Lets say I have CD to App/Recipe and I use this "ng g c recipe-item" it will be generated in App folder instead of Recipe. enter image description here

2 Answers 2

8

if you want to generate a new component called recipe-item inside of the recipe directory:

ng g c recipe/recipe-item

See page 2: https://cli.angular.io/reference.pdf -> ng generate -> Valid types: -> component

Sign up to request clarification or add additional context in comments.

Comments

0

as shown on angular-cli page

components support relative path generation

try using

ng g component recipe-item

5 Comments

From the documentation it shows that, but when I try it it doesn't work. I have edited the quoin by adding a screen shot of the same.
src/app/new-cmp/new-cmp.component.html is created corrected by the ng g component recipe-item. check your folder structure once.
What I want to achieve here is src/app/test/newcmp.component.html. I am already at in the folder Geralds-MacBook-Pro:test gbrigens$.
it is going to create a separate folder for your component (that's how cli works). if you want to achieve src/app/test/newcmp.component.html then you have to manually add the files (which i won't recommend). when you would have executed ng g component test then test folder with all the component files were created. so if you want to have new-cmp component file in test folder, then you have to manually do it . running ng g component xyz would create xyz folder with all the component files. hope I'm clear.
Yea, you are right, if I don't want to create a folder for it I will use "--flat" flag, If you have time check out this tutorial from mindspace youtube.com/watch?v=DBjPIabiRNg min31 the guy generates components in the same path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.