How to Create a new module in Angular ?
Last Updated :
20 Mar, 2024
Modules are most important when it comes to building strong and scalable Angular applications. They help organize your code, promote modularity, and improve maintainability. It encourages collaboration among developers by grouping related components, directives, pipes, and services.
In this article, we will see how to create a new module in Angular.
What is Module in Angular?
Module in Angular refers to a place where you can group the Components, directives, pipes, and services that are related to the application. The simplest way to create a module is using Angular CLI. NgModules are Angular libraries such as FormsModule, HttpClientModule, and RouterModule. NgModules can also be used to access third-party libraries such as AngularFire2, Ionic, and Material Design.
Steps to Create a new Module in Angular:
There are mainly two methods for creating a module:
- Using the Angular CLI
- Manually Creating Module
Creating Module Using the Angular CLI:
In most cases this Approach is highly recommended ,as it is easy, quick and Efficient. Angular provides you command to generate new Modules,
Step 1: Open your terminal or Command prompt and go to the root directory of your Project.
Step 2: Run the Following Command ,in place of '[name]' write your desired module name,
ng generate module [name]
you can also make this command short by using
ng g m [name]
create moduleManually Creating new module
Step 1. Go to app Directory, right click on it select New folder and give it a name.

Step 2: In that folder right click and select new file and name it as "job.module.ts" or anything else of your choice.


Step 3: Now we have to Import ng module from '@angular/core' and add some lines of code in
Node
//job.module.ts
import { NgModule } from '@angular/core";
@NgModule({
declarations: [],
imports: [],
providers: [],
bootstrap: [],
})
export class JobModule {
}
And Remember to add your components, services , and elements to the arrays as in the above code.
Example- write 'ng g c job/job --flat' to create a component using flat if you do not want to create separate folder for your components.


Now you can declare your job components in array ,you can also add other components and import other modules.

Step 4: Now as we have declare module, we can import Job Module in other module and use it component of that module.
Example- I want to use job module in app module then
1. just open the module, in import part write 'JobModule' to import it and before that export job component
Node
@NgModule({
declarations: [JobComponent],
imports: [],
providers: [],
bootstrap: [],
exports: [JobComponent],|
})
export class JobModule {
}
2. Once that is done, you will be able to see suggestion in app component.

3. Now if you will reload job component content is visible.

Similar Reads
How to create module with Routing in Angular 9 ?
Angular applications are modular, and NgModules is Angular's own modular architecture. NgModules are containers for closely integrated application domains, workflows, or feature sets that comprise cohesive code blocks. Their scope is governed by the NgModule they include, and they can contain compon
4 min read
How to create a new component in Angular?
A component in Angular is the building block for making web pages. It is a reusable block of code that can be used anywhere in the app any number of times. It provides scalability, reusability, and readability. Each component does a specific job like showing a menu, a photo or a card, etc. In this a
3 min read
How to Create Todo List in Angular 7 ?
The ToDo app is used to help us to remember some important task. We just add the task and when accomplished, delete them. This to-do list uses various Bootstrap classes that make our web application not only attractive but also responsive. Approach: Create a new angular app using following command:
2 min read
How to Create Modules in Node.js ?
Modules are the building blocks of NodeJS code. They help you break down your project into smaller, manageable pieces, each with its own job. To create a module, just make a JavaScript file and export what you want to share. Other files can then import and use those exports, adding that functionalit
3 min read
How to create a custom pipe in AngularJS ?
In this article, we will learn how to generate custom pipe other than using built-in pipe in Angular & also explore its implementation. The Pipe is a function that is used to modify the data before rendering it to the user. Some of the pre-built pipes are date, uppercase, lowercase, currency, de
6 min read
How to create class in Angular Project?
In Angular, TypeScript is the primary language for writing code. One of the fundamental concepts in TypeScript is classes, which allow you to define blueprints for creating objects with properties and methods. In this article, we'll explore how to create classes in Angular projects and understand th
2 min read
Create Project with App Module in Angular 17
When you try to create the Angular 17 application, you notice that the app.module.ts file is missing. Angular 17 introduces a significant change with Standalone configuration as the default in projects. But if you still want to work with the old folder structure then follow this article to the end.
6 min read
How to Get All Route Params/Data in Angular?
In Angular, managing route parameters and extracting data from routes is important for creating dynamic and responsive web applications. Route parameters allow you to pass information in URLs, and accessing this data enables your application to make decisions and render content dynamically. This art
4 min read
How to Enable HTML 5 Mode in Angular 1.x ?
HTML5 mode in Angular1.x is the configuration that replaces the default hash-based URLs and provides more user-friendly URLs using the HTML5 History API. This feature mainly enhances our one-page application and also provides a better experience to the users. We need to configure our server with pro
6 min read
How to make an http call in angular
Angular, with its robust framework and extensive ecosystem, offers you powerful tools for building modern web applications. One such tool is the HttpClient module, which provides a seamless way to make HTTP calls and interact with RESTful APIs or backend services. In this article, we'll explore maki
3 min read