NgModules
Angular NgModules are also classes with ‘@NgModule’ and it has metadata that describe how the different parts of the application will work together. Like javascript modules have their own files but NgModule does not have their own file, they only include metadata. it also helps to organise that component and services of the angular application.
Syntax: An NgModule is defined using the @NgModule decorator, which accepts a metadata object containing various configuration options such as declarations, imports, providers, and exports.
import { NgModule } from '@angular/core';
@NgModule({
declarations: [ /* components, directives, and pipes */ ],
imports: [ /* imported modules */ ],
providers: [ /* services */ ],
exports: [ /* exported components, directives, and pipes */ ]
})
export class MyModule { }
Differece between JavaScript Modules & NgModule
Modules play an important role in structuring and organizing the code of Javascript and Angular.js. They help us to use the code efficiently. Majorly NgModule in Angular.js and Modules in Javascript are widely used in different scenarios.
In this article, We will learn about Modules and their importance in Angular.js and Javascript.
Table of Content
- Javascript Modules
- Features of JavaScript Modules
- NgModules
- Features of NgModules
- Difference between NgModule and JavaScript Modules
- Conclusion