What is the difference between declarations, providers, and import in NgModule? Last Updated : 24 Sep, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report Let us first discuss about these terms: Declarations: Declarations are used to declare components, directives, pipes that belongs to the current module. Everything inside declarations knows each other.Declarations are used to make directives (including components and pipes) from the current module available to other directives in the current module.Selectors of directives, components or pipes are only matched against the HTML if they are declared or imported.Providers: Providers are used to make services and values known to dependency injection.They are added to the root scope and they are injected to other services or directives that have them as dependency.Imports:Imports makes the exported declarations of other modules available in the current module.It is used to import supporting modules likes FormsModule, RouterModule, CommonModule etc. Differences: Declarations Providers Imports Declarations are used to make directives.Providers are used to make services.Imports makes the exported declarations of other modules available in the current module.Used to declare components, directives, pipes that belongs to the current module.Used to inject the services required by components, directives, pipes in our module.Used to import supporting modules likes FormsModule, RouterModule, etc.Ex. AppComponent.Ex. StateService.Ex. BrowserModule. Defined in Declarations array in @NgModule @NgModule({ declarations: [ ], )} Defined in Providers array in @NgModule. @NgModule({ providers: [ ], )} Defined in imports array in @NgModule. @NgModule({ imports: [], )} An example in which all three declarations, imports and providers are used: The providers used in this project is custom service named UserService. ng g s User user.service.ts javascript import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root' }) export class UserService { constructor() { } } This UserService is used as provider in app.module.ts. app.module.ts javascript // imports for the application import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { HttpClientModule } from '@angular/common/http'; import { FormsModule } from '@angular/forms'; import { AppRoutingModule } from './app-routing.module'; // declarations for the application import { AppComponent } from './app.component'; // providers for the application import { UserService } from './user.service'; @NgModule({ declarations: [ AppComponent, ], imports: [ BrowserModule, AppRoutingModule, HttpClientModule, FormsModule ], providers: [UserService], bootstrap: [AppComponent] }) export class AppModule { } app.component.html html <h1>GeeksforGeeks</h1> <ul> <li>imports in this app: BrowserModule, AppRoutingModule, HttpClientModule, FormsModule</li> <li>declarations in this app: AppComponent</li> <li>providers in this app: UserService</li> </ul> Output: Comment More infoAdvertise with us Next Article What is the Difference Between $routeProvider and $stateProvider in AngularJS ? T taran910 Follow Improve Article Tags : Web Technologies AngularJS AngularJS-Misc Similar Reads What is the difference between export.create and router.post? export.create and router.post are used in the context of backend frameworks like Express JS. They both are used for handling HTTP requests and operate at different levels within the framework. In this article we will learn about export.create and router.post and see the key differences between them. 3 min read What is the difference between Service Directive and Module in Angular ? Angular is a Typescript framework used to build dynamic and Single-Page Applications. This has a strong focus on modularity and reusability of code which helps in creating complex and maintainable applications. At the core, Angular has 3 fundamental building blocks, i.e., Service, Directive and Modu 6 min read What is the Difference Between factory and service in AngularJS ? AngularJS is a JavaScript-based framework. It can be used by adding it to an HTML page using a <script> tag. AngularJS helps in extending the HTML attributes with the help of directives and binding of data to the HTML with expressions. In this article, we will explore the differences between t 4 min read What is the Difference Between $routeProvider and $stateProvider in AngularJS ? In AngularJS, as we create Single-Page Applications, we need to implement the routing of components to view those images without having full page reloads. This can be achieved with the most popular routing methods, i.e., $routeProvider (ngRoute) and $stateProvider (ui-router).In this article, we wil 5 min read What is the Difference between Constructor and ngOnInit in AngularJS ? Constructor: Constructor is the default method for a class that is created when a class is installed and ensures the proper execution of the roles in the class and its subsections. Angular are preferably the Dependency Injector (DI), analyzes the builder's components and when creating a new feature 3 min read What's the difference between an Angular Component and Module? In this article, we will explore the Components & Modules in Angular, along with knowing the basic implementation & lastly, will know the differences between them. Component: In Angular, a Component is a piece of code that represents a view. It is responsible for rendering the content and ha 6 min read Like