Let us first discuss about these terms:
- 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 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 makes the exported declarations of other modules available in the current module.
- It is used to import supporting modules likes FormsModule, RouterModule, CommonModule etc.
|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
declarations: [ ],
Defined in Providers array in @NgModule.
providers: [ ],
Defined in imports array in @NgModule.
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
This UserService is used as provider in app.module.ts.
- Difference between declarations and entryComponents in AngularJS
- What is entryComponents in angular ngModule ?
- Difference between node.js require and ES6 import and export
- ES6 | Import and Export
- Import and Export in Node.js
- Why import star in Python is a bad idea
- Different ways to import csv file in Pandas
- CSS | @import rule
- What is the best way to include CSS file? Why use @import?
- import command in Linux with Examples
- How to import Google Fonts in HTML ?
- SASS | @import
- How to import config.php file in a PHP script ?
- How to Import another TypeScript Files ?
- How to import SASS through npm ?
- How to import LESS through npm ?
- How to import data from .CSV file into MySQL table using Node.js ?
- Difference Between DOS and Windows
- Difference Between Apache Kafka and Apache Flume
- Difference between Bootstrap and AngularJS
Improved By : bunnyram19