feat(core): allow to add precompiled tokens via a provider

Introduces the new `ANALYZE_FOR_PRECOMPILE` token. This token can be used to
create a virtual provider that will populate the `precompile` fields of
components and app modules based on its
`useValue`. All components that are referenced in the `useValue`
value (either directly or in a nested array or map) will be added
to the `precompile` property.

closes #9874
related to #9726
This commit is contained in:
Tobias Bosch
2016-07-07 10:05:55 -07:00
parent 9d265b6f61
commit 7073cf74fe
12 changed files with 215 additions and 30 deletions

View File

@ -7,7 +7,7 @@
*/
import {LowerCasePipe, NgIf} from '@angular/common';
import {AppModule, Component, ComponentFactoryResolver, Injectable} from '@angular/core';
import {ANALYZE_FOR_PRECOMPILE, AppModule, Component, ComponentFactoryResolver, Inject, Injectable, OpaqueToken} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
@Injectable()
@ -53,3 +53,17 @@ export class SomeModule {
})
export class SomeModuleUsingParentComp {
}
export const SOME_TOKEN = new OpaqueToken('someToken');
export function provideValueWithPrecompile(value: any) {
return [
{provide: SOME_TOKEN, useValue: value},
{provide: ANALYZE_FOR_PRECOMPILE, useValue: value, multi: true},
];
}
@AppModule({providers: [provideValueWithPrecompile([{a: 'b', component: SomeComp}])]})
export class SomeModuleWithAnalyzePrecompileProvider {
constructor(@Inject(SOME_TOKEN) public providedValue: any) {}
}