Angular applications are supposed to be designed in a modular way. Everything is supposed to be a small standalone reusable chunk. Angular Module is used to create modules. According to Angular.io "NgModules are containers for a cohesive block of code dedicated to an
application domain, a workflow, or a closely related set of capabilities".
Every Angular app has at least one NgModule class, the root module, which is conventionally named
Every Angular app has at least one NgModule class, the root module, which is conventionally named
AppModule and resides in a file named app.module.ts. You launch your app by bootstrapping the root NgModule.NgModule metadata
NgModule is defined by a class decorated with@NgModule(). The @NgModule()
decorator is a function that takes a single metadata object, whose
properties describe the module. The most important properties are as
follows.
-
declarations: This declares all the components, directives, and pipes that belong to this specific NgModule.
-
exports: The subset of declarations that should be visible and usable in the component templates of other NgModules.
-
imports: Other modules whose exported classes are needed by component templates declared in this NgModule.
-
providers: Creators of services that this NgModule contributes to the global collection of services; they become accessible in all parts of the app. (You can also specify providers at the component level, which is often preferred.)
-
bootstrap: The main application view, called the root component, which hosts all other app views. Only the root NgModule should set thebootstrapproperty.
Sample Angular Module
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
@NgModule({
imports: [ BrowserModule ],
providers: [ Logger ],
declarations: [ AppComponent ],
exports: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }


0 Comments