Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

How to generate components in a specific folder with Angular CLI?

I am using Angular 4 with Angular CLI and I am able to create a new component with the following command.

E:\HiddenWords>ng generate component plainsight

But I need to generate a child component inside plainsight. Is there a way to do it with Angular CLI?
by

3 Answers

rahul07
The ng g component plainsight/some-name makes a new directory when we use it.

The final output will be:

plainsight/some-name/some-name.component.ts

To avoid that, make use of the flat option ng g component plainsight/some-name --flat and it will generate the files without making a new folder

plainsight/some-name.component.ts
RoliMishra
Quick, Simple and Error free method
i.e. You want to create a component in a app/common folder as shown in the image given below, then follow these steps

Right-click on the folder in which you want to create component.
Select option Open in Integrated Terminal or Open in Command Prompt.
In the new terminal (you'll see your selected path), then type ng g c my-component.
sandhya6gczb
Create a component inside a specific folder:

ng g c folder-name/component-name

Create a component inside a folder for a specific (existing) module with Angular-CLI:

ng g c folder-name/component-name --module=folder-name/moduleName.module.ts

Login / Signup to Answer the Question.