feat(core): introduce ModuleWithProviders.

Modules can now provider helper functions that allow
to import a module together with an array of providers.

Part of #10043
This commit is contained in:
Tobias Bosch
2016-07-25 01:39:50 -07:00
parent d6b65db9a7
commit f02da4e91a
6 changed files with 90 additions and 21 deletions
+3 -3
View File
@@ -16,13 +16,13 @@ import {ChangeDetectionStrategy} from '../src/change_detection/change_detection'
import {AnimationEntryMetadata} from './animation/metadata';
import {AttributeMetadata, ContentChildMetadata, ContentChildrenMetadata, QueryMetadata, ViewChildMetadata, ViewChildrenMetadata, ViewQueryMetadata} from './metadata/di';
import {ComponentMetadata, DirectiveMetadata, HostBindingMetadata, HostListenerMetadata, InputMetadata, OutputMetadata, PipeMetadata} from './metadata/directives';
import {NgModuleMetadata} from './metadata/ng_module';
import {ModuleWithProviders, NgModuleMetadata} from './metadata/ng_module';
import {ViewEncapsulation, ViewMetadata} from './metadata/view';
export {ANALYZE_FOR_ENTRY_COMPONENTS, AttributeMetadata, ContentChildMetadata, ContentChildrenMetadata, QueryMetadata, ViewChildMetadata, ViewChildrenMetadata, ViewQueryMetadata} from './metadata/di';
export {ComponentMetadata, DirectiveMetadata, HostBindingMetadata, HostListenerMetadata, InputMetadata, OutputMetadata, PipeMetadata} from './metadata/directives';
export {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, DoCheck, OnChanges, OnDestroy, OnInit} from './metadata/lifecycle_hooks';
export {NgModuleMetadata} from './metadata/ng_module';
export {ModuleWithProviders, NgModuleMetadata} from './metadata/ng_module';
export {ViewEncapsulation, ViewMetadata} from './metadata/view';
import {makeDecorator, makeParamDecorator, makePropDecorator, TypeDecorator,} from './util/decorators';
@@ -498,7 +498,7 @@ export interface NgModuleMetadataFactory {
(obj?: {
providers?: any[],
declarations?: Array<Type|any[]>,
imports?: Array<Type|any[]>,
imports?: Array<Type|ModuleWithProviders|any[]>,
exports?: Array<Type|any[]>,
entryComponents?: Array<Type|any[]>
}): NgModuleDecorator;
@@ -9,6 +9,16 @@
import {InjectableMetadata} from '../di/metadata';
import {Type} from '../facade/lang';
/**
* A wrapper around a module that also includes the providers.
*
* @experimental
*/
export interface ModuleWithProviders {
ngModule: Type;
providers?: any[];
}
/**
* Declares an Angular Module.
* @experimental
@@ -65,6 +75,7 @@ export class NgModuleMetadata extends InjectableMetadata {
/**
* Specifies a list of modules whose exported directives/pipes
* should be available to templates in this module.
* This can also contain {@link ModuleWithProviders}.
*
* ### Example
*
@@ -76,7 +87,7 @@ export class NgModuleMetadata extends InjectableMetadata {
* }
* ```
*/
imports: Array<Type|any[]>;
imports: Array<Type|ModuleWithProviders|any[]>;
/**
* Specifies a list of directives/pipes/module that can be used within the template