Generate module with component and routing in Angular 8 (using angular cli command)

Nirali picture Nirali · Jun 14, 2019 · Viewed 28.2k times · Source

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 ?

Answer

nash11 picture nash11 · Jun 14, 2019

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