Generating Component inside other folder in Angular CLI

In this Angular article we will learn about Generating Component inside folder.

In some of the scenarios, you may need to create component inside other folder.
For example,
You want to separate your components based on modules, at this situation you may need to create your component inside other folder.

Generating Component inside folder :

When you use this Angular CLI command:

ng generate component first-component

It will create folder called first-component and will generate files inside of it as following.

First Components Angular

And Now if you want to create component inside module1 folder, you can use the following command:

Now you can see that second-component is created inside module1 folder.

Second Components

The same way you can create hierarchy

ng generate component main-module/sub-module/third-component

This will generate directory structure as follows:

third components

That’s pretty much it 😄 Happy Coding!

I hope you like this  article.:)

Also Read :