Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng generate component in subdirectory

I have the following directory structure

enter image description here

I would like to create a new page, let's say, an About page. I want to put it in src/app/page/about/*

So I try:

ng generate component pages/about 

but I get this error:

Error: More than one module matches. Use skip-import option to skip importing the component into the closest module. More than one module matches. Use skip-import option to skip importing the component into the closest module. 

Is it a good idea to use pages to store my separate pages? How can I generate components in a subdirectory using the angular-cli?

like image 900
Alexander Mills Avatar asked Jan 04 '18 20:01

Alexander Mills


People also ask

Does Ng generate component create folder?

We can use ng generate component command to create component in sub-directory or specific folder.


1 Answers

Because there are 2 modules (app.module.ts, shared.module.ts) found the CLI does not know which module to declare your component in. To get around this you have to tell the CLI which module you wish to declare your component in with the module option

ng generate component pages/about --module=app.module // or ng generate component pages/about --module=shared.module 
like image 146
Brocco Avatar answered Sep 21 '22 09:09

Brocco