1

I've attached folder hierarchy of my angular project below:

enter image description here

As you can here. My app folder is under _component folder. also, my other ts files like auth is under _auth folder, interfaces are inside _model folder etc.

You when I execute ng g c componentName command, it creates app folder in root and create component inside it. so I have to go to particular folder and then I need to execute command.

enter image description here

My question is, is there anyway that I can create component direct from my root folder. like ng g c _component/MycomponentName

Updated:
I've also tried other ways to create it like below:
enter image description here enter image description here

Ubiquitous Developers
  • 3,637
  • 6
  • 33
  • 78

4 Answers4

2

This is the normal command, to be run in the project root.

ng g c path/to/name

But due to your non-standard project structure, ng is failing to find the NgModule in which your new component should be imported. So you either can use the --skip-import option, or the --module path/to/your/app/module option and point ng to the right file

nsndvd
  • 800
  • 8
  • 21
0

It's better to change your project structure into standard angular project structure like this.enter image description here

then you can generate new component moving relevant place through terminal and type

ng g c component name

0

how to create Component inside folder in Angular example with image

ANS : ng generate component auth/reset-password

Arun
  • 63
  • 1
  • 4
0

Better you could use following folder structure and get rid of that error so that you can create modules and components accordingly.

-app
  
-shared
  -services
  -pipes
  -components
  -models

-modules_folder
  -module_A
    -components_folder
        -component_A.component.ts
        -component_A.component.html
        -component_A.component.css            
    -models_folder
        -model_A.model.ts
    -services_folder
        -service_A.service.ts

    -module_A.component.ts 
    -module_A.component.html
    -module_A.component.css
    -module_A.module.ts        
    -module_A-routing.module.ts  

-app.component.ts
-app.component.html
-app.component.css
-app.module.ts
-app-routing.module.ts

Above folder structure gives a kind of micro-service architecture as well where each module having its own services/dependencies.

Salahuddin Ahmed
  • 4,854
  • 4
  • 14
  • 35