What is the difference between declarations, providers, and import in NgModule? Last Updated : 24 Sep, 2020 Comments Improve Suggest changes 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 Spring Boot Tutorial T taran910 Follow Improve Article Tags : Web Technologies AngularJS AngularJS-Misc Similar Reads Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co 11 min read JavaScript Tutorial JavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.JavaScript on Client Side: On the client side, Jav 11 min read Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance 10 min read React Interview Questions and Answers React is an efficient, flexible, and open-source JavaScript library that allows developers to create simple, fast, and scalable web applications. Jordan Walke, a software engineer who was working for Facebook, created React. Developers with a JavaScript background can easily develop web applications 15+ min read React Tutorial React is a powerful JavaScript library for building fast, scalable front-end applications. Created by Facebook, it's known for its component-based structure, single-page applications (SPAs), and virtual DOM,enabling efficient UI updates and a seamless user experience.Note: The latest stable version 7 min read JavaScript Interview Questions and Answers JavaScript is the most used programming language for developing websites, web servers, mobile applications, and many other platforms. In Both Front-end and Back-end Interviews, JavaScript was asked, and its difficulty depends upon the on your profile and company. Here, we compiled 70+ JS Interview q 15+ min read Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact 12 min read Python Variables In Python, variables are used to store data that can be referenced and manipulated during program execution. A variable is essentially a name that is assigned to a value. Unlike many other programming languages, Python variables do not require explicit declaration of type. The type of the variable i 6 min read Spring Boot Interview Questions and Answers Spring Boot is a Java-based framework used to develop stand-alone, production-ready applications with minimal configuration. Introduced by Pivotal in 2014, it simplifies the development of Spring applications by offering embedded servers, auto-configuration, and fast startup. Many top companies, inc 15+ min read Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and 9 min read Like