NgModule

Stable Interface

Interface Overview

interface NgModule {
  providers : Provider[]
  declarations : Array<Type<any>|any[]>
  imports : Array<Type<any>|ModuleWithProviders|any[]>
  exports : Array<Type<any>|any[]>
  entryComponents : Array<Type<any>|any[]>
  bootstrap : Array<Type<any>|any[]>
  schemas : Array<SchemaMetadata|any[]>
  id : string
}

Interface Description

NgModule decorator and metadata

Interface Details

providers : Provider[]

Defines the set of injectable objects that are available in the injector of this module.

Simple Example

Here is an example of a class that can be injected:

class Greeter {
   greet(name:string) {
     return 'Hello ' + name + '!';
   }
}

@NgModule({
  providers: [
    Greeter
  ]
})
class HelloWorld {
  greeter:Greeter;

  constructor(greeter:Greeter) {
    this.greeter = greeter;
  }
}
declarations : Array<Type<any>|any[]>

Specifies a list of directives/pipes that belong to this module.

@NgModule({
  declarations: [NgFor]
})
class CommonModule {
}
imports : Array<Type<any>|ModuleWithProviders|any[]>

Specifies a list of modules whose exported directives/pipes should be available to templates in this module. This can also contain ModuleWithProviders.

@NgModule({
  imports: [CommonModule]
})
class MainModule {
}
exports : Array<Type<any>|any[]>

Specifies a list of directives/pipes/module that can be used within the template of any component that is part of an angular module that imports this angular module.

@NgModule({
  exports: [NgFor]
})
class CommonModule {
}
entryComponents : Array<Type<any>|any[]>

Defines the components that should be compiled as well when this component is defined. For each components listed here, Angular will create a ComponentFactory and store it in the ComponentFactoryResolver.

bootstrap : Array<Type<any>|any[]>

Defines the components that should be bootstrapped when this module is bootstrapped. The components listed here will automatically be added to entryComponents.

schemas : Array<SchemaMetadata|any[]>

Elements and properties that are not angular Components nor Directives have to be declared in the schema.

Available schemas:

  • NO_ERRORS_SCHEMA: any elements and properties are allowed,
  • CUSTOM_ELEMENTS_SCHEMA: any custom elements (tag name has "-") with any properties are allowed.
id : string

An opaque ID for this module, e.g. a name or a path. Used to identify modules in getModuleFactory. If left undefined, the NgModule will not be registered with getModuleFactory.

exported from @angular/core/index, defined in @angular/core/src/metadata/ng_module.ts

doc_Angular
2016-10-06 09:46:45
Comments
Leave a Comment

Please login to continue.