11

I have created new angular project using angular cli command ng new my-app

Then, I wanted to create module named landing-page inside src/app directory, so i used command ng g m landing-page --routing=true which creates two files i.e. one module and one its routing file as following :

src/app/landing-page/landing-page-routing.module.ts (254 bytes) 

src/app/landing-page/landing-page.module.ts (300 bytes)

but Now, instead of that i want to create module with its root component and routing both in single folder named as landing-page, so how can i do that with single cli command ?

Nirali
  • 454
  • 1
  • 6
  • 16

4 Answers4

24

There is no way to do this as of yet in one single command other than creating your own schematic command as mentioned in the comments because the module and component are two different schematics and as per the documentation, the <schematic> argument in ng g <schematic> [options] can only take one sub-command.

You can, however, combine two commands in one line using && and create a module and the component in the same folder.

ng g m landing-page --routing=true && ng g c landing-page --skip-tests=true -m=landing-page
nash11
  • 8,220
  • 3
  • 19
  • 55
13

Use --module app.module which helps to update in app.module.

Below command creates a home module, a component with a routing module.

ng g m home --routing=true --module app.module && ng g c home

I would like to suggest you use lazy loading routing which helps in a big application for route lazy loading and app performance.

User below command to create a module, component, route and it will also update your app-routing.module.ts.

ng g m home --route home --module app.module
Kiran Mali
  • 597
  • 4
  • 12
3

ng g m Header --route header --module app.module

this command create , parent module , parent component , and routing , try it .. tc

0

This command create module, component and routes in angular

1

ng g m admin --routing=true --module app.module && ng g c admin

vimuth
  • 5,064
  • 33
  • 79
  • 116