Angular Decorator @NgModule - Study24x7
Social learning Network


New to Study24X7 ?

 Join Now

Angular Decorator @NgModule

Updated on 15 February 2020
Angular Programming
7 min read 3 views
Updated on 15 February 2020


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

2. Imports

3. Providers

4. Bootstrap 

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. 


declarations: [ 

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 


imports: [ 

BrowserModule //By Default Angular project import browser module



3. Providers-

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. 


providers: [./app.service.ts]



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 


providedIn: "root"



But we can also be able to stick with the previous Syntax and we can pass service file name in Providers array. 

Write a comment...
Related Posts