linkNgModule
npm Package | @angular/core |
---|---|
Module | import { NgModule } from '@angular/core'; |
Source | core/src/metadata/ng_module.ts |
linkMetadata Overview
@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
})
linkDescription
NgModule decorator and metadata.
linkMetadata Properties
providers?: Provider[]
Defines the set of injectable objects that are available in the injector of this module.
linkSimple 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.
linkExample
@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
.
linkExample
@NgModule({
imports: [CommonModule]
})
class MainModule {
}
exports?: Array<Type<any> | any[]>
Specifies a list of directives/pipes/modules that can be used within the template of any component that is part of an Angular module that imports this Angular module.
linkExample
@NgModule({
exports: [NgFor]
})
class CommonModule {
}
entryComponents?: Array<Type<any> | any[]>
Specifies a list of components that should be compiled when this module is defined.
For each component 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
.