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
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
|
|
import {ANALYZE_FOR_PRECOMPILE, Component, ComponentFactoryResolver, Inject, OpaqueToken} from '@angular/core';
|
|
|
|
import {BasicComp} from './basic';
|
|
|
|
@Component({selector: 'cmp-precompile', template: '', precompile: [BasicComp]})
|
|
export class CompWithPrecompile {
|
|
constructor(public cfr: ComponentFactoryResolver) {}
|
|
}
|
|
|
|
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},
|
|
];
|
|
}
|
|
|
|
@Component({
|
|
selector: 'comp-precompile-provider',
|
|
template: '',
|
|
providers: [provideValueWithPrecompile([{a: 'b', component: BasicComp}])]
|
|
})
|
|
export class CompWithAnalyzePrecompileProvider {
|
|
constructor(public cfr: ComponentFactoryResolver, @Inject(SOME_TOKEN) public providedValue: any) {
|
|
}
|
|
}
|