NgModule is a decorator present in the app.module.ts. And it is imported through the @Angular/core module. @NgModule is basically used for defining the purpose of import like It is used for basically 4 purposes:-
1. Declarations -
In NgModule decorator we pass an Object having declarations as a key through which we define the component as the part of App. Through this, we can declare the component which is used in the app. As an example, AppComponent is byDefault imported when we create an Angular Project by CLI.
AppComponent //App component is declared as the part of the Application
2. Imports -
In Ngmodule decorator, we pass Object having another key as imports. Which is used for importing the 3rd party features in our own project
BrowserModule //By Default Angular project import browser module
It is used for declaring the service file which is used by the project to communicate with other components without using complex @Input and @Output Architecture of communication.
4. Bootstrap -
It is used to let know the angular project that used that component to display the content. By Default AppComponent is included.
bootstrap: [AppComponent] }
Note - In Above Angular 6+ app, we can lazy load the service file by
But we can also be able to stick with the previous Syntax and we can pass service file name in Providers array.