ng generate component in subdirectory

Alexander Mills picture Alexander Mills · Jan 4, 2018 · Viewed 39.3k times · Source

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?

Answer

Brocco picture Brocco · Jan 5, 2018

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