Angular NgModule API

Angular NgModule API

Angular NgModules configure the injector and the compiler and help organize related things together.

An NgModule is a class marked by the @NgModule decorator. @NgModule takes a metadata object that describes how to compile a component’s template and how to create an injector at runtime. It identifies the module’s own components, directives, and pipes, making some of them public, through the exports property, so that external components can use them. @NgModule can also add service providers to the application dependency injectors.

At a high level, NgModules are a way to organize Angular apps and they accomplish this through the metadata in the @NgModule decorator. The metadata falls into three categories:

 

  • Static: Compiler configuration which tells the compiler about directive selectors and where in templates the directives should be applied through selector matching. This is configured via the declarations array.
  • Runtime: Injector configuration via the providers array.
  • Composability/Grouping: Bringing NgModules together and making them available via the imports and exports arrays.

 

@NgModule({

// Static, that is compiler configuration

declarations: [], // Configure the selectors

entryComponents: [], // Generate the host factory

 

// Runtime, or injector configuration

providers: [], // Runtime injector configuration

 

// Composability / Grouping

imports: [], // composing NgModules together

exports: [] // making NgModules available to other parts of the app

})

 

@NgModule metadata

IT Professionals, Web Developers, Web Programmers, IT students can Apply for the certification course to move ahead in their careers.

Angular 4 Tutorial IndexBack to Angular 4 Tutorial Main Page

Angular Sharing Modules
Angular Libraries

Get industry recognized certification – Contact us

keyboard_arrow_up
Open chat
Need help?
Hello 👋
Can we help you?