This article explains in short about the difference between the JavaScript modules and NgModules and that how they are used in Angular.
Modules help organize our code and use it in an efficient way. The manner in which the code is organised is different for JavaScript and Angular but the ultimate purpose of a module remains the same.
However, any Angular application that we create depends on both the ways.
A JavaScript Module is a code written in JavaScript which means to organize it and this module comes into action by making use of an export statement like this:
export class MyComponent {}
An NgModule is the use of a module decorated by the decoratorĀ @NgModule.Ā The imports array inside the decorator tells Angular that these modules will be needed for the current scenario. This goes like:
https://gist.github.com/NishuGoel/740f711b893002b074c6b556effc8612
An NgModule differs from the JS Modules specifically because unlike JS Modules, NgModules do not have their own file. Also they need the presence of the decorator @NgModule and its metadata.
An NgModule has a declarations list wherein it defines all the member classes and it bounds declarable classes.
Some of the frequently use NgModules are BrowserModule, FormsModule, CommonModule etc.