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 ?
Run ng generate to create the application routing module.
After creating successfully app, we need to create module using angular cli command. angular provide command to create module with routing in angular application. so let's run bellow command to create admin module: run successfully command, it will create files as like bellow path:
After creating successfully app, we need to create module using angular cli command. angular provide command to create module with routing in angular application. so let's run bellow command to create admin module: run successfully command, it will create files as like bellow path: Read Also: How to Create Custom Pipe in Angular 9/8?
The declaring NgModule. The name of the project. The route path for a lazy-loaded module. When supplied, creates a component in the new module, and adds the route to that component in the Routes array declared in the module provided in the --module option.
Where path is the URL segment and component is the component to be loaded. This route tells angular to render HomeComponent when the user navigates to the URL “/home” Next, we register the routes with the RouterModule in our AppModule as shown below
ng g m Header --route header --module app.module
this command create , parent module , parent component , and routing , try it .. tc
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With