How to generate Module with Routing in angular
command to generate module having routing file in angular
In this article, You will be going to know that how you can generate modules in an angular project using the CLI command.
In Angular, a module is a mechanism to group components, directives, pipes and services that are related, in such a way that can be combined with other modules to create an application.
ng generate module Test
This causes the CLI to create a folder called Test
with a file inside called Test.module.ts
Test.module.ts
This file will have content as mentioned below:
import { NgModule } from ‘@angular/core’;
import { CommonModule } from ‘@angular/common’;@NgModule({
imports: [
CommonModule
],
declarations: []
})
export class Test{ }
Module with Routing File
This causes the CLI to create a folder called Test
with files inside called Test.module.ts
and Test-routing.module.ts
ng generate module Test --routing
Test-routing.module.ts
Routing helps to navigate from one view to another in angular.This file will have content as mentioned below:
import { NgModule } from ‘@angular/core’;import { RouterModule, Routes } from ‘@angular/router’;
@NgModule({imports: [RouterModule.forChild(routes)],exports: [RouterModule],})export class TestRoutingModule {}
Conclusion
Here are more topics of angular
How to generate Component in Angular
How to use ngx Data Table in Angular Project
Which Angular Version I Am Using
How to Create Toastr in Angular Project