DEV Community

ismail-dinar
ismail-dinar

Posted on

Angular in a Nutshell #Part1: MODULES

In Angular, a module is a class marked by @NgModule decorator that contains components, directives, pipes, and services.
An Angular application has at least one module.

import { NgModule } from '@angular/core';

@NgModule({
  declarations: ...,
  imports: ...,
  exports: ...,
  providers: ...,
  bootstrap: ...
})

class MyModule {} 
Enter fullscreen mode Exit fullscreen mode
  • Declarations: List of components, directives, and pipes that belong to this module.
declarations: [HelloComponent, TranslatePipe] 
Enter fullscreen mode Exit fullscreen mode
  • Imports: List of modules to import into this module. Everything from the imported modules (components, directives, pipes) is available to the declarations of this module.
imports: [BrowserModule, SomeOtherModule] 
Enter fullscreen mode Exit fullscreen mode
  • Exports: List of components, directives, and pipes visible to modules that import this module.
exports: [HelloComponent, TranslatePipe] 
Enter fullscreen mode Exit fullscreen mode
  • Providers: List of dependency injection providers visible both to the contents of this module and to importers of this module.
providers: [ApiService, { provide: UserService }]  
Enter fullscreen mode Exit fullscreen mode
  • Bootstrap: List of components to bootstrap when this module is bootstrapped.
bootstrap: [HelloComponent] 
Enter fullscreen mode Exit fullscreen mode

Top comments (0)