refactor(core): rename `precompile` into `entryComponents`.

Part of #10043

BREAKING CHANGE:
- `@Component.precompile` was renamed to `@Component.entryComponents`
  (old property still works but is deprecated)
- `ANALYZE_FOR_PRECOMPILE` was renamed to `ANALYZE_FOR_ENTRY_COMPONENTS` (no deprecations)
This commit is contained in:
Tobias Bosch 2016-07-25 00:36:30 -07:00
parent 46b212706b
commit 6f4e49ed53
37 changed files with 296 additions and 294 deletions

View File

@ -38,7 +38,7 @@ export class MyComponent {}
@NgModule({ @NgModule({
imports: [BrowserModule], imports: [BrowserModule],
declarations: [MyComponent], declarations: [MyComponent],
precompile: [MyComponent] entryComponents: [MyComponent]
}) })
export class MainModule { export class MainModule {
constructor(appRef: ApplicationRef) { constructor(appRef: ApplicationRef) {

View File

@ -0,0 +1,35 @@
/**
* @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_ENTRY_COMPONENTS, Component, ComponentFactoryResolver, Inject, OpaqueToken} from '@angular/core';
import {BasicComp} from './basic';
@Component({selector: 'cmp-entryComponents', template: '', entryComponents: [BasicComp]})
export class CompWithEntryComponents {
constructor(public cfr: ComponentFactoryResolver) {}
}
export const SOME_TOKEN = new OpaqueToken('someToken');
export function provideValueWithEntryComponents(value: any) {
return [
{provide: SOME_TOKEN, useValue: value},
{provide: ANALYZE_FOR_ENTRY_COMPONENTS, useValue: value, multi: true},
];
}
@Component({
selector: 'comp-entryComponents-provider',
template: '',
providers: [provideValueWithEntryComponents([{a: 'b', component: BasicComp}])]
})
export class CompWithAnalyzeEntryComponentsProvider {
constructor(public cfr: ComponentFactoryResolver, @Inject(SOME_TOKEN) public providedValue: any) {
}
}

View File

@ -12,23 +12,24 @@ import {BrowserModule} from '@angular/platform-browser';
import {AnimateCmp} from './animate'; import {AnimateCmp} from './animate';
import {BasicComp} from './basic'; import {BasicComp} from './basic';
import {CompWithAnalyzeEntryComponentsProvider, CompWithEntryComponents} from './entry_components';
import {CompWithProviders, CompWithReferences} from './features'; import {CompWithProviders, CompWithReferences} from './features';
import {CompUsingRootModuleDirectiveAndPipe, SomeDirectiveInRootModule, SomeLibModule, SomePipeInRootModule, SomeService} from './module_fixtures'; import {CompUsingRootModuleDirectiveAndPipe, SomeDirectiveInRootModule, SomeLibModule, SomePipeInRootModule, SomeService} from './module_fixtures';
import {CompWithAnalyzePrecompileProvider, CompWithPrecompile} from './precompile';
import {ProjectingComp} from './projection'; import {ProjectingComp} from './projection';
import {CompWithChildQuery, CompWithDirectiveChild} from './queries'; import {CompWithChildQuery, CompWithDirectiveChild} from './queries';
@NgModule({ @NgModule({
declarations: [ declarations: [
SomeDirectiveInRootModule, SomePipeInRootModule, AnimateCmp, BasicComp, CompWithPrecompile, SomeDirectiveInRootModule, SomePipeInRootModule, AnimateCmp, BasicComp, CompWithEntryComponents,
CompWithAnalyzePrecompileProvider, ProjectingComp, CompWithChildQuery, CompWithDirectiveChild, CompWithAnalyzeEntryComponentsProvider, ProjectingComp, CompWithChildQuery,
CompUsingRootModuleDirectiveAndPipe, CompWithProviders, CompWithReferences CompWithDirectiveChild, CompUsingRootModuleDirectiveAndPipe, CompWithProviders,
CompWithReferences
], ],
imports: [BrowserModule, FormsModule, SomeLibModule], imports: [BrowserModule, FormsModule, SomeLibModule],
providers: [SomeService], providers: [SomeService],
precompile: [ entryComponents: [
AnimateCmp, BasicComp, CompWithPrecompile, CompWithAnalyzePrecompileProvider, ProjectingComp, AnimateCmp, BasicComp, CompWithEntryComponents, CompWithAnalyzeEntryComponentsProvider,
CompWithChildQuery, CompUsingRootModuleDirectiveAndPipe ProjectingComp, CompWithChildQuery, CompUsingRootModuleDirectiveAndPipe
] ]
}) })
export class MainModule { export class MainModule {

View File

@ -7,7 +7,7 @@
*/ */
import {LowerCasePipe, NgIf} from '@angular/common'; import {LowerCasePipe, NgIf} from '@angular/common';
import {ANALYZE_FOR_PRECOMPILE, Component, ComponentFactoryResolver, Directive, Inject, Injectable, Input, NgModule, OpaqueToken, Pipe} from '@angular/core'; import {ANALYZE_FOR_ENTRY_COMPONENTS, Component, ComponentFactoryResolver, Directive, Inject, Injectable, Input, NgModule, OpaqueToken, Pipe} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser'; import {BrowserModule} from '@angular/platform-browser';
@Injectable() @Injectable()
@ -51,19 +51,19 @@ export class CompUsingLibModuleDirectiveAndPipe {
export const SOME_TOKEN = new OpaqueToken('someToken'); export const SOME_TOKEN = new OpaqueToken('someToken');
export function provideValueWithPrecompile(value: any) { export function provideValueWithEntryComponents(value: any) {
return [ return [
{provide: SOME_TOKEN, useValue: value}, {provide: SOME_TOKEN, useValue: value},
{provide: ANALYZE_FOR_PRECOMPILE, useValue: value, multi: true}, {provide: ANALYZE_FOR_ENTRY_COMPONENTS, useValue: value, multi: true},
]; ];
} }
@NgModule({ @NgModule({
declarations: [SomeDirectiveInLibModule, SomePipeInLibModule, CompUsingLibModuleDirectiveAndPipe], declarations: [SomeDirectiveInLibModule, SomePipeInLibModule, CompUsingLibModuleDirectiveAndPipe],
precompile: [CompUsingLibModuleDirectiveAndPipe], entryComponents: [CompUsingLibModuleDirectiveAndPipe],
providers: [ providers: [
ServiceUsingLibModule, ServiceUsingLibModule,
provideValueWithPrecompile([{a: 'b', component: CompUsingLibModuleDirectiveAndPipe}]) provideValueWithEntryComponents([{a: 'b', component: CompUsingLibModuleDirectiveAndPipe}])
], ],
}) })
export class SomeLibModule { export class SomeLibModule {

View File

@ -1,35 +0,0 @@
/**
* @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) {
}
}

View File

@ -9,23 +9,24 @@
import './init'; import './init';
import {BasicComp} from '../src/basic'; import {BasicComp} from '../src/basic';
import {CompWithAnalyzePrecompileProvider, CompWithPrecompile} from '../src/precompile'; import {CompWithAnalyzeEntryComponentsProvider, CompWithEntryComponents} from '../src/entry_components';
import {createComponent} from './util'; import {createComponent} from './util';
describe('content projection', () => { describe('content projection', () => {
it('should support precompile in components', () => { it('should support entryComponents in components', () => {
var compFixture = createComponent(CompWithPrecompile); var compFixture = createComponent(CompWithEntryComponents);
var cf = compFixture.componentInstance.cfr.resolveComponentFactory(BasicComp); var cf = compFixture.componentInstance.cfr.resolveComponentFactory(BasicComp);
expect(cf.componentType).toBe(BasicComp); expect(cf.componentType).toBe(BasicComp);
}); });
it('should support precompile via the ANALYZE_FOR_PRECOMPILE provider and function providers in components', it('should support entryComponents via the ANALYZE_FOR_ENTRY_COMPONENTS provider and function providers in components',
() => { () => {
const compFixture = createComponent(CompWithAnalyzePrecompileProvider); const compFixture = createComponent(CompWithAnalyzeEntryComponentsProvider);
const cf = compFixture.componentInstance.cfr.resolveComponentFactory(BasicComp); const cf = compFixture.componentInstance.cfr.resolveComponentFactory(BasicComp);
expect(cf.componentType).toBe(BasicComp); expect(cf.componentType).toBe(BasicComp);
// check that the function call that created the provider for ANALYZE_FOR_PRECOMPILE worked. // check that the function call that created the provider for ANALYZE_FOR_ENTRY_COMPONENTS
// worked.
expect(compFixture.componentInstance.providedValue).toEqual([ expect(compFixture.componentInstance.providedValue).toEqual([
{a: 'b', component: BasicComp} {a: 'b', component: BasicComp}
]); ]);

View File

@ -20,7 +20,7 @@ describe('NgModule', () => {
expect(moduleRef.injector.get(SomeService) instanceof SomeService).toBe(true); expect(moduleRef.injector.get(SomeService) instanceof SomeService).toBe(true);
}); });
it('should support precompile components', () => { it('should support entryComponents components', () => {
const moduleRef = createModule(); const moduleRef = createModule();
const cf = moduleRef.componentFactoryResolver.resolveComponentFactory( const cf = moduleRef.componentFactoryResolver.resolveComponentFactory(
CompUsingRootModuleDirectiveAndPipe); CompUsingRootModuleDirectiveAndPipe);
@ -29,13 +29,14 @@ describe('NgModule', () => {
expect(compRef.instance instanceof CompUsingRootModuleDirectiveAndPipe).toBe(true); expect(compRef.instance instanceof CompUsingRootModuleDirectiveAndPipe).toBe(true);
}); });
it('should support precompile via the ANALYZE_FOR_PRECOMPILE provider and function providers in components', it('should support entryComponents via the ANALYZE_FOR_ENTRY_COMPONENTS provider and function providers in components',
() => { () => {
const moduleRef = createModule(); const moduleRef = createModule();
const cf = moduleRef.componentFactoryResolver.resolveComponentFactory( const cf = moduleRef.componentFactoryResolver.resolveComponentFactory(
CompUsingRootModuleDirectiveAndPipe); CompUsingRootModuleDirectiveAndPipe);
expect(cf.componentType).toBe(CompUsingRootModuleDirectiveAndPipe); expect(cf.componentType).toBe(CompUsingRootModuleDirectiveAndPipe);
// check that the function call that created the provider for ANALYZE_FOR_PRECOMPILE worked. // check that the function call that created the provider for ANALYZE_FOR_ENTRY_COMPONENTS
// worked.
expect(moduleRef.injector.get(SOME_TOKEN)).toEqual([ expect(moduleRef.injector.get(SOME_TOKEN)).toEqual([
{a: 'b', component: CompUsingLibModuleDirectiveAndPipe} {a: 'b', component: CompUsingLibModuleDirectiveAndPipe}
]); ]);

View File

@ -405,7 +405,7 @@ export class CompileTemplateMetadata {
export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier { export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier {
static create( static create(
{type, isComponent, selector, exportAs, changeDetection, inputs, outputs, host, {type, isComponent, selector, exportAs, changeDetection, inputs, outputs, host,
lifecycleHooks, providers, viewProviders, queries, viewQueries, precompile, template}: { lifecycleHooks, providers, viewProviders, queries, viewQueries, entryComponents, template}: {
type?: CompileTypeMetadata, type?: CompileTypeMetadata,
isComponent?: boolean, isComponent?: boolean,
selector?: string, selector?: string,
@ -421,7 +421,7 @@ export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier {
Array<CompileProviderMetadata|CompileTypeMetadata|CompileIdentifierMetadata|any[]>, Array<CompileProviderMetadata|CompileTypeMetadata|CompileIdentifierMetadata|any[]>,
queries?: CompileQueryMetadata[], queries?: CompileQueryMetadata[],
viewQueries?: CompileQueryMetadata[], viewQueries?: CompileQueryMetadata[],
precompile?: CompileTypeMetadata[], entryComponents?: CompileTypeMetadata[],
template?: CompileTemplateMetadata template?: CompileTemplateMetadata
} = {}): CompileDirectiveMetadata { } = {}): CompileDirectiveMetadata {
var hostListeners: {[key: string]: string} = {}; var hostListeners: {[key: string]: string} = {};
@ -470,7 +470,7 @@ export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier {
viewProviders, viewProviders,
queries, queries,
viewQueries, viewQueries,
precompile, entryComponents,
template, template,
}); });
} }
@ -490,13 +490,13 @@ export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier {
queries: CompileQueryMetadata[]; queries: CompileQueryMetadata[];
viewQueries: CompileQueryMetadata[]; viewQueries: CompileQueryMetadata[];
// Note: Need to keep types here to prevent cycles! // Note: Need to keep types here to prevent cycles!
precompile: CompileTypeMetadata[]; entryComponents: CompileTypeMetadata[];
template: CompileTemplateMetadata; template: CompileTemplateMetadata;
constructor( constructor(
{type, isComponent, selector, exportAs, changeDetection, inputs, outputs, hostListeners, {type, isComponent, selector, exportAs, changeDetection, inputs, outputs, hostListeners,
hostProperties, hostAttributes, lifecycleHooks, providers, viewProviders, queries, hostProperties, hostAttributes, lifecycleHooks, providers, viewProviders, queries,
viewQueries, precompile, template}: { viewQueries, entryComponents, template}: {
type?: CompileTypeMetadata, type?: CompileTypeMetadata,
isComponent?: boolean, isComponent?: boolean,
selector?: string, selector?: string,
@ -514,7 +514,7 @@ export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier {
Array<CompileProviderMetadata|CompileTypeMetadata|CompileIdentifierMetadata|any[]>, Array<CompileProviderMetadata|CompileTypeMetadata|CompileIdentifierMetadata|any[]>,
queries?: CompileQueryMetadata[], queries?: CompileQueryMetadata[],
viewQueries?: CompileQueryMetadata[], viewQueries?: CompileQueryMetadata[],
precompile?: CompileTypeMetadata[], entryComponents?: CompileTypeMetadata[],
template?: CompileTemplateMetadata, template?: CompileTemplateMetadata,
} = {}) { } = {}) {
this.type = type; this.type = type;
@ -532,7 +532,7 @@ export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier {
this.viewProviders = _normalizeArray(viewProviders); this.viewProviders = _normalizeArray(viewProviders);
this.queries = _normalizeArray(queries); this.queries = _normalizeArray(queries);
this.viewQueries = _normalizeArray(viewQueries); this.viewQueries = _normalizeArray(viewQueries);
this.precompile = _normalizeArray(precompile); this.entryComponents = _normalizeArray(entryComponents);
this.template = template; this.template = template;
} }
@ -619,8 +619,8 @@ export class CompileNgModuleMetadata implements CompileMetadataWithIdentifier {
exportedDirectives: CompileDirectiveMetadata[]; exportedDirectives: CompileDirectiveMetadata[];
declaredPipes: CompilePipeMetadata[]; declaredPipes: CompilePipeMetadata[];
exportedPipes: CompilePipeMetadata[]; exportedPipes: CompilePipeMetadata[];
// Note: See CompileDirectiveMetadata.precompile why this has to be a type. // Note: See CompileDirectiveMetadata.entryComponents why this has to be a type.
precompile: CompileTypeMetadata[]; entryComponents: CompileTypeMetadata[];
providers: CompileProviderMetadata[]; providers: CompileProviderMetadata[];
importedModules: CompileNgModuleMetadata[]; importedModules: CompileNgModuleMetadata[];
@ -630,7 +630,7 @@ export class CompileNgModuleMetadata implements CompileMetadataWithIdentifier {
constructor( constructor(
{type, providers, declaredDirectives, exportedDirectives, declaredPipes, exportedPipes, {type, providers, declaredDirectives, exportedDirectives, declaredPipes, exportedPipes,
precompile, importedModules, exportedModules, transitiveModule}: { entryComponents, importedModules, exportedModules, transitiveModule}: {
type?: CompileTypeMetadata, type?: CompileTypeMetadata,
providers?: providers?:
Array<CompileProviderMetadata|CompileTypeMetadata|CompileIdentifierMetadata|any[]>, Array<CompileProviderMetadata|CompileTypeMetadata|CompileIdentifierMetadata|any[]>,
@ -638,7 +638,7 @@ export class CompileNgModuleMetadata implements CompileMetadataWithIdentifier {
exportedDirectives?: CompileDirectiveMetadata[], exportedDirectives?: CompileDirectiveMetadata[],
declaredPipes?: CompilePipeMetadata[], declaredPipes?: CompilePipeMetadata[],
exportedPipes?: CompilePipeMetadata[], exportedPipes?: CompilePipeMetadata[],
precompile?: CompileTypeMetadata[], entryComponents?: CompileTypeMetadata[],
importedModules?: CompileNgModuleMetadata[], importedModules?: CompileNgModuleMetadata[],
exportedModules?: CompileNgModuleMetadata[], exportedModules?: CompileNgModuleMetadata[],
transitiveModule?: TransitiveCompileNgModuleMetadata transitiveModule?: TransitiveCompileNgModuleMetadata
@ -649,7 +649,7 @@ export class CompileNgModuleMetadata implements CompileMetadataWithIdentifier {
this.declaredPipes = _normalizeArray(declaredPipes); this.declaredPipes = _normalizeArray(declaredPipes);
this.exportedPipes = _normalizeArray(exportedPipes); this.exportedPipes = _normalizeArray(exportedPipes);
this.providers = _normalizeArray(providers); this.providers = _normalizeArray(providers);
this.precompile = _normalizeArray(precompile); this.entryComponents = _normalizeArray(entryComponents);
this.importedModules = _normalizeArray(importedModules); this.importedModules = _normalizeArray(importedModules);
this.exportedModules = _normalizeArray(exportedModules); this.exportedModules = _normalizeArray(exportedModules);
this.transitiveModule = transitiveModule; this.transitiveModule = transitiveModule;
@ -670,7 +670,7 @@ export class TransitiveCompileNgModuleMetadata {
pipesSet = new Set<Type>(); pipesSet = new Set<Type>();
constructor( constructor(
public modules: CompileNgModuleMetadata[], public providers: CompileProviderMetadata[], public modules: CompileNgModuleMetadata[], public providers: CompileProviderMetadata[],
public precompile: CompileTypeMetadata[], public directives: CompileDirectiveMetadata[], public entryComponents: CompileTypeMetadata[], public directives: CompileDirectiveMetadata[],
public pipes: CompilePipeMetadata[]) { public pipes: CompilePipeMetadata[]) {
directives.forEach(dir => this.directivesSet.add(dir.type.runtime)); directives.forEach(dir => this.directivesSet.add(dir.type.runtime));
pipes.forEach(pipe => this.pipesSet.add(pipe.type.runtime)); pipes.forEach(pipe => this.pipesSet.add(pipe.type.runtime));

View File

@ -254,7 +254,7 @@ function _cloneDirectiveWithTemplate(
viewProviders: directive.viewProviders, viewProviders: directive.viewProviders,
queries: directive.queries, queries: directive.queries,
viewQueries: directive.viewQueries, viewQueries: directive.viewQueries,
precompile: directive.precompile, entryComponents: directive.entryComponents,
template: template template: template
}); });
} }

View File

@ -143,7 +143,7 @@ export class DirectiveResolver {
changeDetection: dm.changeDetection, changeDetection: dm.changeDetection,
providers: dm.providers, providers: dm.providers,
viewProviders: dm.viewProviders, viewProviders: dm.viewProviders,
precompile: dm.precompile entryComponents: dm.entryComponents
}); });
} else { } else {

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {ANALYZE_FOR_PRECOMPILE, ChangeDetectionStrategy, ChangeDetectorRef, ComponentFactory, ComponentFactoryResolver, ElementRef, Injector, NgModuleFactory, QueryList, RenderComponentType, Renderer, SecurityContext, SimpleChange, TemplateRef, ViewContainerRef, ViewEncapsulation} from '@angular/core'; import {ANALYZE_FOR_ENTRY_COMPONENTS, ChangeDetectionStrategy, ChangeDetectorRef, ComponentFactory, ComponentFactoryResolver, ElementRef, Injector, NgModuleFactory, QueryList, RenderComponentType, Renderer, SecurityContext, SimpleChange, TemplateRef, ViewContainerRef, ViewEncapsulation} from '@angular/core';
import {AnimationGroupPlayer as AnimationGroupPlayer_, AnimationKeyframe as AnimationKeyframe_, AnimationSequencePlayer as AnimationSequencePlayer_, AnimationStyles as AnimationStyles_, AppElement, AppView, ChangeDetectorStatus, CodegenComponentFactoryResolver, DebugAppView, DebugContext, EMPTY_ARRAY, EMPTY_MAP, NgModuleInjector, NoOpAnimationPlayer as NoOpAnimationPlayer_, StaticNodeDebugInfo, TemplateRef_, UNINITIALIZED, ValueUnwrapper, ViewType, ViewUtils, balanceAnimationKeyframes as impBalanceAnimationKeyframes, castByValue, checkBinding, clearStyles as impClearStyles, collectAndResolveStyles as impCollectAndResolveStyles, devModeEqual, flattenNestedViewRenderNodes, interpolate, prepareFinalAnimationStyles as impBalanceAnimationStyles, pureProxy1, pureProxy10, pureProxy2, pureProxy3, pureProxy4, pureProxy5, pureProxy6, pureProxy7, pureProxy8, pureProxy9, renderStyles as impRenderStyles} from '../core_private'; import {AnimationGroupPlayer as AnimationGroupPlayer_, AnimationKeyframe as AnimationKeyframe_, AnimationSequencePlayer as AnimationSequencePlayer_, AnimationStyles as AnimationStyles_, AppElement, AppView, ChangeDetectorStatus, CodegenComponentFactoryResolver, DebugAppView, DebugContext, EMPTY_ARRAY, EMPTY_MAP, NgModuleInjector, NoOpAnimationPlayer as NoOpAnimationPlayer_, StaticNodeDebugInfo, TemplateRef_, UNINITIALIZED, ValueUnwrapper, ViewType, ViewUtils, balanceAnimationKeyframes as impBalanceAnimationKeyframes, castByValue, checkBinding, clearStyles as impClearStyles, collectAndResolveStyles as impCollectAndResolveStyles, devModeEqual, flattenNestedViewRenderNodes, interpolate, prepareFinalAnimationStyles as impBalanceAnimationStyles, pureProxy1, pureProxy10, pureProxy2, pureProxy3, pureProxy4, pureProxy5, pureProxy6, pureProxy7, pureProxy8, pureProxy9, renderStyles as impRenderStyles} from '../core_private';
@ -58,10 +58,10 @@ var impNoOpAnimationPlayer = NoOpAnimationPlayer_;
var ANIMATION_STYLE_UTIL_ASSET_URL = assetUrl('core', 'animation/animation_style_util'); var ANIMATION_STYLE_UTIL_ASSET_URL = assetUrl('core', 'animation/animation_style_util');
export class Identifiers { export class Identifiers {
static ANALYZE_FOR_PRECOMPILE = new CompileIdentifierMetadata({ static ANALYZE_FOR_ENTRY_COMPONENTS = new CompileIdentifierMetadata({
name: 'ANALYZE_FOR_PRECOMPILE', name: 'ANALYZE_FOR_ENTRY_COMPONENTS',
moduleUrl: assetUrl('core', 'metadata/di'), moduleUrl: assetUrl('core', 'metadata/di'),
runtime: ANALYZE_FOR_PRECOMPILE runtime: ANALYZE_FOR_ENTRY_COMPONENTS
}); });
static ViewUtils = new CompileIdentifierMetadata( static ViewUtils = new CompileIdentifierMetadata(
{name: 'ViewUtils', moduleUrl: assetUrl('core', 'linker/view_utils'), runtime: impViewUtils}); {name: 'ViewUtils', moduleUrl: assetUrl('core', 'linker/view_utils'), runtime: impViewUtils});

View File

@ -123,7 +123,7 @@ export class CompileMetadataResolver {
var changeDetectionStrategy: ChangeDetectionStrategy = null; var changeDetectionStrategy: ChangeDetectionStrategy = null;
var viewProviders: Array<cpl.CompileProviderMetadata|cpl.CompileTypeMetadata|any[]> = []; var viewProviders: Array<cpl.CompileProviderMetadata|cpl.CompileTypeMetadata|any[]> = [];
var moduleUrl = staticTypeModuleUrl(directiveType); var moduleUrl = staticTypeModuleUrl(directiveType);
var precompileTypes: cpl.CompileTypeMetadata[] = []; var entryComponentTypes: cpl.CompileTypeMetadata[] = [];
if (dirMeta instanceof ComponentMetadata) { if (dirMeta instanceof ComponentMetadata) {
var cmpMeta = <ComponentMetadata>dirMeta; var cmpMeta = <ComponentMetadata>dirMeta;
var viewMeta = this._viewResolver.resolve(directiveType); var viewMeta = this._viewResolver.resolve(directiveType);
@ -150,9 +150,10 @@ export class CompileMetadataResolver {
verifyNonBlankProviders(directiveType, dirMeta.viewProviders, 'viewProviders'), []); verifyNonBlankProviders(directiveType, dirMeta.viewProviders, 'viewProviders'), []);
} }
moduleUrl = componentModuleUrl(this._reflector, directiveType, cmpMeta); moduleUrl = componentModuleUrl(this._reflector, directiveType, cmpMeta);
if (cmpMeta.precompile) { if (cmpMeta.entryComponents) {
precompileTypes = flattenArray(cmpMeta.precompile) entryComponentTypes =
.map((cmp) => this.getTypeMetadata(cmp, staticTypeModuleUrl(cmp))); flattenArray(cmpMeta.entryComponents)
.map((cmp) => this.getTypeMetadata(cmp, staticTypeModuleUrl(cmp)));
} }
} }
@ -160,7 +161,7 @@ export class CompileMetadataResolver {
if (isPresent(dirMeta.providers)) { if (isPresent(dirMeta.providers)) {
providers = this.getProvidersMetadata( providers = this.getProvidersMetadata(
verifyNonBlankProviders(directiveType, dirMeta.providers, 'providers'), verifyNonBlankProviders(directiveType, dirMeta.providers, 'providers'),
precompileTypes); entryComponentTypes);
} }
var queries: cpl.CompileQueryMetadata[] = []; var queries: cpl.CompileQueryMetadata[] = [];
var viewQueries: cpl.CompileQueryMetadata[] = []; var viewQueries: cpl.CompileQueryMetadata[] = [];
@ -184,7 +185,7 @@ export class CompileMetadataResolver {
viewProviders: viewProviders, viewProviders: viewProviders,
queries: queries, queries: queries,
viewQueries: viewQueries, viewQueries: viewQueries,
precompile: precompileTypes entryComponents: entryComponentTypes
}); });
this._directiveCache.set(directiveType, meta); this._directiveCache.set(directiveType, meta);
} }
@ -259,7 +260,8 @@ export class CompileMetadataResolver {
if (declaredDirMeta = this.getDirectiveMetadata(declaredType, false)) { if (declaredDirMeta = this.getDirectiveMetadata(declaredType, false)) {
this._addDirectiveToModule( this._addDirectiveToModule(
declaredDirMeta, moduleType, transitiveModule, declaredDirectives, true); declaredDirMeta, moduleType, transitiveModule, declaredDirectives, true);
// Collect @Component.directives/pipes/precompile into our declared directives/pipes. // Collect @Component.directives/pipes/entryComponents into our declared
// directives/pipes.
this._getTransitiveViewDirectivesAndPipes( this._getTransitiveViewDirectivesAndPipes(
declaredDirMeta, moduleType, transitiveModule, declaredDirectives, declaredPipes); declaredDirMeta, moduleType, transitiveModule, declaredDirectives, declaredPipes);
} else if (declaredPipeMeta = this.getPipeMetadata(declaredType, false)) { } else if (declaredPipeMeta = this.getPipeMetadata(declaredType, false)) {
@ -273,22 +275,23 @@ export class CompileMetadataResolver {
} }
const providers: any[] = []; const providers: any[] = [];
const precompile: cpl.CompileTypeMetadata[] = []; const entryComponents: cpl.CompileTypeMetadata[] = [];
if (meta.providers) { if (meta.providers) {
providers.push(...this.getProvidersMetadata(meta.providers, precompile)); providers.push(...this.getProvidersMetadata(meta.providers, entryComponents));
} }
if (meta.precompile) { if (meta.entryComponents) {
precompile.push(...flattenArray(meta.precompile) entryComponents.push(
.map(type => this.getTypeMetadata(type, staticTypeModuleUrl(type)))); ...flattenArray(meta.entryComponents)
.map(type => this.getTypeMetadata(type, staticTypeModuleUrl(type))));
} }
transitiveModule.precompile.push(...precompile); transitiveModule.entryComponents.push(...entryComponents);
transitiveModule.providers.push(...providers); transitiveModule.providers.push(...providers);
compileMeta = new cpl.CompileNgModuleMetadata({ compileMeta = new cpl.CompileNgModuleMetadata({
type: this.getTypeMetadata(moduleType, staticTypeModuleUrl(moduleType)), type: this.getTypeMetadata(moduleType, staticTypeModuleUrl(moduleType)),
providers: providers, providers: providers,
precompile: precompile, entryComponents: entryComponents,
declaredDirectives: declaredDirectives, declaredDirectives: declaredDirectives,
exportedDirectives: exportedDirectives, exportedDirectives: exportedDirectives,
declaredPipes: declaredPipes, declaredPipes: declaredPipes,
@ -306,7 +309,7 @@ export class CompileMetadataResolver {
addComponentToModule(moduleType: Type, compType: Type) { addComponentToModule(moduleType: Type, compType: Type) {
const moduleMeta = this.getNgModuleMetadata(moduleType); const moduleMeta = this.getNgModuleMetadata(moduleType);
// Collect @Component.directives/pipes/precompile into our declared directives/pipes. // Collect @Component.directives/pipes/entryComponents into our declared directives/pipes.
const compMeta = this.getDirectiveMetadata(compType, false); const compMeta = this.getDirectiveMetadata(compType, false);
this._addDirectiveToModule( this._addDirectiveToModule(
compMeta, moduleMeta.type.runtime, moduleMeta.transitiveModule, compMeta, moduleMeta.type.runtime, moduleMeta.transitiveModule,
@ -315,8 +318,8 @@ export class CompileMetadataResolver {
compMeta, moduleMeta.type.runtime, moduleMeta.transitiveModule, compMeta, moduleMeta.type.runtime, moduleMeta.transitiveModule,
moduleMeta.declaredDirectives, moduleMeta.declaredPipes); moduleMeta.declaredDirectives, moduleMeta.declaredPipes);
moduleMeta.transitiveModule.precompile.push(compMeta.type); moduleMeta.transitiveModule.entryComponents.push(compMeta.type);
moduleMeta.precompile.push(compMeta.type); moduleMeta.entryComponents.push(compMeta.type);
this._verifyModule(moduleMeta); this._verifyModule(moduleMeta);
} }
@ -335,17 +338,17 @@ export class CompileMetadataResolver {
} }
}); });
moduleMeta.declaredDirectives.forEach((dirMeta) => { moduleMeta.declaredDirectives.forEach((dirMeta) => {
dirMeta.precompile.forEach((precompileComp) => { dirMeta.entryComponents.forEach((entryComponent) => {
if (!moduleMeta.transitiveModule.directivesSet.has(precompileComp.runtime)) { if (!moduleMeta.transitiveModule.directivesSet.has(entryComponent.runtime)) {
throw new BaseException( throw new BaseException(
`Component ${stringify(dirMeta.type.runtime)} in NgModule ${stringify(moduleMeta.type.runtime)} uses ${stringify(precompileComp.runtime)} via "precompile" but it was neither declared nor imported into the module!`); `Component ${stringify(dirMeta.type.runtime)} in NgModule ${stringify(moduleMeta.type.runtime)} uses ${stringify(entryComponent.runtime)} via "entryComponents" but it was neither declared nor imported into the module!`);
} }
}); });
}); });
moduleMeta.precompile.forEach((precompileType) => { moduleMeta.entryComponents.forEach((entryComponentType) => {
if (!moduleMeta.transitiveModule.directivesSet.has(precompileType.runtime)) { if (!moduleMeta.transitiveModule.directivesSet.has(entryComponentType.runtime)) {
throw new BaseException( throw new BaseException(
`NgModule ${stringify(moduleMeta.type.runtime)} uses ${stringify(precompileType.runtime)} via "precompile" but it was neither declared nor imported!`); `NgModule ${stringify(moduleMeta.type.runtime)} uses ${stringify(entryComponentType.runtime)} via "entryComponents" but it was neither declared nor imported!`);
} }
}); });
} }
@ -400,17 +403,18 @@ export class CompileMetadataResolver {
private _getTransitiveNgModuleMetadata( private _getTransitiveNgModuleMetadata(
importedModules: cpl.CompileNgModuleMetadata[], importedModules: cpl.CompileNgModuleMetadata[],
exportedModules: cpl.CompileNgModuleMetadata[]): cpl.TransitiveCompileNgModuleMetadata { exportedModules: cpl.CompileNgModuleMetadata[]): cpl.TransitiveCompileNgModuleMetadata {
// collect `providers` / `precompile` from all imported and all exported modules // collect `providers` / `entryComponents` from all imported and all exported modules
const transitiveModules = getTransitiveModules(importedModules.concat(exportedModules), true); const transitiveModules = getTransitiveModules(importedModules.concat(exportedModules), true);
const providers = flattenArray(transitiveModules.map((ngModule) => ngModule.providers)); const providers = flattenArray(transitiveModules.map((ngModule) => ngModule.providers));
const precompile = flattenArray(transitiveModules.map((ngModule) => ngModule.precompile)); const entryComponents =
flattenArray(transitiveModules.map((ngModule) => ngModule.entryComponents));
const transitiveExportedModules = getTransitiveModules(importedModules, false); const transitiveExportedModules = getTransitiveModules(importedModules, false);
const directives = const directives =
flattenArray(transitiveExportedModules.map((ngModule) => ngModule.exportedDirectives)); flattenArray(transitiveExportedModules.map((ngModule) => ngModule.exportedDirectives));
const pipes = flattenArray(transitiveExportedModules.map((ngModule) => ngModule.exportedPipes)); const pipes = flattenArray(transitiveExportedModules.map((ngModule) => ngModule.exportedPipes));
return new cpl.TransitiveCompileNgModuleMetadata( return new cpl.TransitiveCompileNgModuleMetadata(
transitiveModules, providers, precompile, directives, pipes); transitiveModules, providers, entryComponents, directives, pipes);
} }
private _addDirectiveToModule( private _addDirectiveToModule(
@ -571,7 +575,7 @@ export class CompileMetadataResolver {
return compileToken; return compileToken;
} }
getProvidersMetadata(providers: any[], targetPrecompileComponents: cpl.CompileTypeMetadata[]): getProvidersMetadata(providers: any[], targetEntryComponents: cpl.CompileTypeMetadata[]):
Array<cpl.CompileProviderMetadata|cpl.CompileTypeMetadata|any[]> { Array<cpl.CompileProviderMetadata|cpl.CompileTypeMetadata|any[]> {
const compileProviders: Array<cpl.CompileProviderMetadata|cpl.CompileTypeMetadata|any[]> = []; const compileProviders: Array<cpl.CompileProviderMetadata|cpl.CompileTypeMetadata|any[]> = [];
providers.forEach((provider) => { providers.forEach((provider) => {
@ -581,11 +585,11 @@ export class CompileMetadataResolver {
} }
let compileProvider: cpl.CompileProviderMetadata|cpl.CompileTypeMetadata|any[]; let compileProvider: cpl.CompileProviderMetadata|cpl.CompileTypeMetadata|any[];
if (isArray(provider)) { if (isArray(provider)) {
compileProvider = this.getProvidersMetadata(provider, targetPrecompileComponents); compileProvider = this.getProvidersMetadata(provider, targetEntryComponents);
} else if (provider instanceof Provider) { } else if (provider instanceof Provider) {
let tokenMeta = this.getTokenMetadata(provider.token); let tokenMeta = this.getTokenMetadata(provider.token);
if (tokenMeta.equalsTo(identifierToken(Identifiers.ANALYZE_FOR_PRECOMPILE))) { if (tokenMeta.equalsTo(identifierToken(Identifiers.ANALYZE_FOR_ENTRY_COMPONENTS))) {
targetPrecompileComponents.push(...this.getPrecompileComponentsFromProvider(provider)); targetEntryComponents.push(...this._getEntryComponentsFromProvider(provider));
} else { } else {
compileProvider = this.getProviderMetadata(provider); compileProvider = this.getProviderMetadata(provider);
} }
@ -602,14 +606,15 @@ export class CompileMetadataResolver {
return compileProviders; return compileProviders;
} }
getPrecompileComponentsFromProvider(provider: Provider): cpl.CompileTypeMetadata[] { private _getEntryComponentsFromProvider(provider: Provider): cpl.CompileTypeMetadata[] {
let components: cpl.CompileTypeMetadata[] = []; let components: cpl.CompileTypeMetadata[] = [];
let collectedIdentifiers: cpl.CompileIdentifierMetadata[] = []; let collectedIdentifiers: cpl.CompileIdentifierMetadata[] = [];
if (provider.useFactory || provider.useExisting || provider.useClass) { if (provider.useFactory || provider.useExisting || provider.useClass) {
throw new BaseException(`The ANALYZE_FOR_PRECOMPILE token only supports useValue!`); throw new BaseException(`The ANALYZE_FOR_ENTRY_COMPONENTS token only supports useValue!`);
} }
if (!provider.multi) { if (!provider.multi) {
throw new BaseException(`The ANALYZE_FOR_PRECOMPILE token only supports 'multi = true'!`); throw new BaseException(
`The ANALYZE_FOR_ENTRY_COMPONENTS token only supports 'multi = true'!`);
} }
convertToCompileValue(provider.useValue, collectedIdentifiers); convertToCompileValue(provider.useValue, collectedIdentifiers);
collectedIdentifiers.forEach((identifier) => { collectedIdentifiers.forEach((identifier) => {

View File

@ -41,12 +41,12 @@ export class NgModuleCompiler {
new ParseLocation(sourceFile, null, null, null), new ParseLocation(sourceFile, null, null, null),
new ParseLocation(sourceFile, null, null, null)); new ParseLocation(sourceFile, null, null, null));
var deps: ComponentFactoryDependency[] = []; var deps: ComponentFactoryDependency[] = [];
var precompileComponents = ngModuleMeta.transitiveModule.precompile.map((precompileComp) => { var entryComponents = ngModuleMeta.transitiveModule.entryComponents.map((entryComponent) => {
var id = new CompileIdentifierMetadata({name: precompileComp.name}); var id = new CompileIdentifierMetadata({name: entryComponent.name});
deps.push(new ComponentFactoryDependency(precompileComp, id)); deps.push(new ComponentFactoryDependency(entryComponent, id));
return id; return id;
}); });
var builder = new _InjectorBuilder(ngModuleMeta, precompileComponents, sourceSpan); var builder = new _InjectorBuilder(ngModuleMeta, entryComponents, sourceSpan);
var providerParser = new NgModuleProviderAnalyzer(ngModuleMeta, extraProviders, sourceSpan); var providerParser = new NgModuleProviderAnalyzer(ngModuleMeta, extraProviders, sourceSpan);
providerParser.parse().forEach((provider) => builder.addProvider(provider)); providerParser.parse().forEach((provider) => builder.addProvider(provider));
@ -75,8 +75,8 @@ class _InjectorBuilder {
constructor( constructor(
private _ngModuleMeta: CompileNgModuleMetadata, private _ngModuleMeta: CompileNgModuleMetadata,
private _precompileComponents: CompileIdentifierMetadata[], private _entryComponents: CompileIdentifierMetadata[], private _sourceSpan: ParseSourceSpan) {
private _sourceSpan: ParseSourceSpan) {} }
addProvider(resolvedProvider: ProviderAst) { addProvider(resolvedProvider: ProviderAst) {
var providerValueExpressions = var providerValueExpressions =
@ -116,8 +116,8 @@ class _InjectorBuilder {
[o.SUPER_EXPR [o.SUPER_EXPR
.callFn([ .callFn([
o.variable(InjectorProps.parent.name), o.variable(InjectorProps.parent.name),
o.literalArr(this._precompileComponents.map( o.literalArr(
(precompiledComponent) => o.importExpr(precompiledComponent))) this._entryComponents.map((entryComponent) => o.importExpr(entryComponent)))
]) ])
.toStmt()]); .toStmt()]);

View File

@ -146,13 +146,13 @@ export class RuntimeCompiler implements Compiler {
templates.add(this._createCompiledTemplate( templates.add(this._createCompiledTemplate(
dirMeta, localModuleMeta.transitiveModule.directives, dirMeta, localModuleMeta.transitiveModule.directives,
localModuleMeta.transitiveModule.pipes)); localModuleMeta.transitiveModule.pipes));
dirMeta.precompile.forEach((precompileType) => { dirMeta.entryComponents.forEach((entryComponentType) => {
templates.add(this._createCompiledHostTemplate(precompileType.runtime)); templates.add(this._createCompiledHostTemplate(entryComponentType.runtime));
}); });
} }
}); });
localModuleMeta.precompile.forEach((precompileType) => { localModuleMeta.entryComponents.forEach((entryComponentType) => {
templates.add(this._createCompiledHostTemplate(precompileType.runtime)); templates.add(this._createCompiledHostTemplate(entryComponentType.runtime));
}); });
}); });
templates.forEach((template) => { templates.forEach((template) => {

View File

@ -92,14 +92,13 @@ export class CompileElement extends CompileNode {
this._instances.add(identifierToken(Identifiers.AppElement), this.appElement); this._instances.add(identifierToken(Identifiers.AppElement), this.appElement);
} }
public createComponentFactoryResolver(precompileComponent: CompileIdentifierMetadata[]) { public createComponentFactoryResolver(entryComponents: CompileIdentifierMetadata[]) {
if (!precompileComponent || precompileComponent.length === 0) { if (!entryComponents || entryComponents.length === 0) {
return; return;
} }
var createComponentFactoryResolverExpr = var createComponentFactoryResolverExpr =
o.importExpr(Identifiers.CodegenComponentFactoryResolver).instantiate([ o.importExpr(Identifiers.CodegenComponentFactoryResolver).instantiate([
o.literalArr(precompileComponent.map( o.literalArr(entryComponents.map((entryComponent) => o.importExpr(entryComponent))),
(precompiledComponent) => o.importExpr(precompiledComponent))),
injectFromViewParentInjector(identifierToken(Identifiers.ComponentFactoryResolver), false) injectFromViewParentInjector(identifierToken(Identifiers.ComponentFactoryResolver), false)
]); ]);
var provider = new CompileProviderMetadata({ var provider = new CompileProviderMetadata({

View File

@ -211,13 +211,13 @@ class ViewBuilderVisitor implements TemplateAstVisitor {
new CompileIdentifierMetadata({name: getViewFactoryName(component, 0)}); new CompileIdentifierMetadata({name: getViewFactoryName(component, 0)});
this.targetDependencies.push( this.targetDependencies.push(
new ViewFactoryDependency(component.type, nestedComponentIdentifier)); new ViewFactoryDependency(component.type, nestedComponentIdentifier));
let precompileComponentIdentifiers = let entryComponentIdentifiers =
component.precompile.map((precompileComp: CompileIdentifierMetadata) => { component.entryComponents.map((entryComponent: CompileIdentifierMetadata) => {
var id = new CompileIdentifierMetadata({name: precompileComp.name}); var id = new CompileIdentifierMetadata({name: entryComponent.name});
this.targetDependencies.push(new ComponentFactoryDependency(precompileComp, id)); this.targetDependencies.push(new ComponentFactoryDependency(entryComponent, id));
return id; return id;
}); });
compileElement.createComponentFactoryResolver(precompileComponentIdentifiers); compileElement.createComponentFactoryResolver(entryComponentIdentifiers);
compViewExpr = o.variable(`compView_${nodeIndex}`); // fix highlighting: ` compViewExpr = o.variable(`compView_${nodeIndex}`); // fix highlighting: `
compileElement.setComponentView(compViewExpr); compileElement.setComponentView(compViewExpr);

View File

@ -21,7 +21,7 @@ class SomeClass5 {}
imports: [SomeClass2], imports: [SomeClass2],
exports: [SomeClass3], exports: [SomeClass3],
providers: [SomeClass4], providers: [SomeClass4],
precompile: [SomeClass5] entryComponents: [SomeClass5]
}) })
class SomeModule { class SomeModule {
} }
@ -41,7 +41,7 @@ export function main() {
imports: [SomeClass2], imports: [SomeClass2],
exports: [SomeClass3], exports: [SomeClass3],
providers: [SomeClass4], providers: [SomeClass4],
precompile: [SomeClass5] entryComponents: [SomeClass5]
})); }));
}); });

View File

@ -116,8 +116,10 @@ export function main() {
describe('compileModuleAsync', () => { describe('compileModuleAsync', () => {
it('should allow to use templateUrl components', fakeAsync(() => { it('should allow to use templateUrl components', fakeAsync(() => {
@NgModule( @NgModule({
{declarations: [SomeCompWithUrlTemplate], precompile: [SomeCompWithUrlTemplate]}) declarations: [SomeCompWithUrlTemplate],
entryComponents: [SomeCompWithUrlTemplate]
})
class SomeModule { class SomeModule {
} }
@ -131,7 +133,8 @@ export function main() {
describe('compileModuleSync', () => { describe('compileModuleSync', () => {
it('should throw when using a templateUrl that has not been compiled before', () => { it('should throw when using a templateUrl that has not been compiled before', () => {
@NgModule({declarations: [SomeCompWithUrlTemplate], precompile: [SomeCompWithUrlTemplate]}) @NgModule(
{declarations: [SomeCompWithUrlTemplate], entryComponents: [SomeCompWithUrlTemplate]})
class SomeModule { class SomeModule {
} }
@ -143,7 +146,7 @@ export function main() {
it('should throw when using a templateUrl in a nested component that has not been compiled before', it('should throw when using a templateUrl in a nested component that has not been compiled before',
() => { () => {
@NgModule({declarations: [SomeComp], precompile: [SomeComp]}) @NgModule({declarations: [SomeComp], entryComponents: [SomeComp]})
class SomeModule { class SomeModule {
} }
@ -158,8 +161,10 @@ export function main() {
it('should allow to use templateUrl components that have been loaded before', it('should allow to use templateUrl components that have been loaded before',
fakeAsync(() => { fakeAsync(() => {
@NgModule( @NgModule({
{declarations: [SomeCompWithUrlTemplate], precompile: [SomeCompWithUrlTemplate]}) declarations: [SomeCompWithUrlTemplate],
entryComponents: [SomeCompWithUrlTemplate]
})
class SomeModule { class SomeModule {
} }

View File

@ -60,7 +60,7 @@ export class MockDirectiveResolver extends DirectiveResolver {
changeDetection: dm.changeDetection, changeDetection: dm.changeDetection,
providers: providers, providers: providers,
viewProviders: viewProviders, viewProviders: viewProviders,
precompile: dm.precompile entryComponents: dm.entryComponents
}); });
} }

View File

@ -65,7 +65,7 @@ export class Compiler {
`Runtime compiler is not loaded. Tried to compile ${stringify(component)}`); `Runtime compiler is not loaded. Tried to compile ${stringify(component)}`);
} }
/** /**
* Compiles the given NgModule. All templates of the components listed in `precompile` * Compiles the given NgModule. All templates of the components listed in `entryComponents`
* have to be either inline or compiled before via `compileComponentAsync` / * have to be either inline or compiled before via `compileComponentAsync` /
* `compileModuleAsync`. Otherwise throws a {@link ComponentStillLoadingError}. * `compileModuleAsync`. Otherwise throws a {@link ComponentStillLoadingError}.
*/ */

View File

@ -14,13 +14,13 @@ import {ComponentFactory} from './component_factory';
* can later be used to create and render a Component instance. * can later be used to create and render a Component instance.
* *
* @deprecated Use {@link ComponentFactoryResolver} together with {@link * @deprecated Use {@link ComponentFactoryResolver} together with {@link
* NgModule}.precompile}/{@link Component}.precompile or * NgModule}.entryComponents}/{@link Component}.entryComponents or
* {@link ANALYZE_FOR_PRECOMPILE} provider for dynamic component creation. * {@link ANALYZE_FOR_ENTRY_COMPONENTS} provider for dynamic component creation.
* Use {@link NgModuleFactoryLoader} for lazy loading. * Use {@link NgModuleFactoryLoader} for lazy loading.
*/ */
export abstract class ComponentResolver { export abstract class ComponentResolver {
static DynamicCompilationDeprecationMsg = static DynamicCompilationDeprecationMsg =
'ComponentResolver is deprecated for dynamic compilation. Use ComponentFactoryResolver together with @NgModule/@Component.precompile or ANALYZE_FOR_PRECOMPILE provider instead. For runtime compile only, you can also use Compiler.compileComponentSync/Async.'; 'ComponentResolver is deprecated for dynamic compilation. Use ComponentFactoryResolver together with @NgModule/@Component.entryComponents or ANALYZE_FOR_ENTRY_COMPONENTS provider instead. For runtime compile only, you can also use Compiler.compileComponentSync/Async.';
static LazyLoadingDeprecationMsg = static LazyLoadingDeprecationMsg =
'ComponentResolver is deprecated for lazy loading. Use NgModuleFactoryLoader instead.'; 'ComponentResolver is deprecated for lazy loading. Use NgModuleFactoryLoader instead.';

View File

@ -29,7 +29,7 @@ export abstract class NgModuleRef<T> {
/** /**
* The ComponentFactoryResolver to get hold of the ComponentFactories * The ComponentFactoryResolver to get hold of the ComponentFactories
* delcared in the `precompile` property of the module. * delcared in the `entryComponents` property of the module.
*/ */
get componentFactoryResolver(): ComponentFactoryResolver { return unimplemented(); } get componentFactoryResolver(): ComponentFactoryResolver { return unimplemented(); }

View File

@ -19,7 +19,7 @@ import {ComponentMetadata, DirectiveMetadata, HostBindingMetadata, HostListenerM
import {NgModuleMetadata} from './metadata/ng_module'; import {NgModuleMetadata} from './metadata/ng_module';
import {ViewEncapsulation, ViewMetadata} from './metadata/view'; import {ViewEncapsulation, ViewMetadata} from './metadata/view';
export {ANALYZE_FOR_PRECOMPILE, AttributeMetadata, ContentChildMetadata, ContentChildrenMetadata, QueryMetadata, ViewChildMetadata, ViewChildrenMetadata, ViewQueryMetadata} from './metadata/di'; 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 {ComponentMetadata, DirectiveMetadata, HostBindingMetadata, HostListenerMetadata, InputMetadata, OutputMetadata, PipeMetadata} from './metadata/directives';
export {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, DoCheck, OnChanges, OnDestroy, OnInit} from './metadata/lifecycle_hooks'; export {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, DoCheck, OnChanges, OnDestroy, OnInit} from './metadata/lifecycle_hooks';
export {NgModuleMetadata} from './metadata/ng_module'; export {NgModuleMetadata} from './metadata/ng_module';
@ -209,7 +209,7 @@ export interface ComponentMetadataFactory {
pipes?: Array<Type|any[]>, pipes?: Array<Type|any[]>,
encapsulation?: ViewEncapsulation, encapsulation?: ViewEncapsulation,
interpolation?: [string, string], interpolation?: [string, string],
precompile?: Array<Type|any[]> entryComponents?: Array<Type|any[]>
}): ComponentDecorator; }): ComponentDecorator;
new (obj: { new (obj: {
selector?: string, selector?: string,
@ -233,7 +233,7 @@ export interface ComponentMetadataFactory {
pipes?: Array<Type|any[]>, pipes?: Array<Type|any[]>,
encapsulation?: ViewEncapsulation, encapsulation?: ViewEncapsulation,
interpolation?: [string, string], interpolation?: [string, string],
precompile?: Array<Type|any[]> entryComponents?: Array<Type|any[]>
}): ComponentMetadata; }): ComponentMetadata;
} }
@ -500,14 +500,14 @@ export interface NgModuleMetadataFactory {
declarations?: Array<Type|any[]>, declarations?: Array<Type|any[]>,
imports?: Array<Type|any[]>, imports?: Array<Type|any[]>,
exports?: Array<Type|any[]>, exports?: Array<Type|any[]>,
precompile?: Array<Type|any[]> entryComponents?: Array<Type|any[]>
}): NgModuleDecorator; }): NgModuleDecorator;
new (obj?: { new (obj?: {
providers?: any[], providers?: any[],
declarations?: Array<Type|any[]>, declarations?: Array<Type|any[]>,
imports?: Array<Type|any[]>, imports?: Array<Type|any[]>,
exports?: Array<Type|any[]>, exports?: Array<Type|any[]>,
precompile?: Array<Type|any[]> entryComponents?: Array<Type|any[]>
}): NgModuleMetadata; }): NgModuleMetadata;
} }

View File

@ -13,12 +13,12 @@ import {StringWrapper, Type, isString, stringify} from '../facade/lang';
/** /**
* This token can be used to create a virtual provider that will populate the * This token can be used to create a virtual provider that will populate the
* `precompile` fields of components and ng modules based on its `useValue`. * `entryComponents` fields of components and ng modules based on its `useValue`.
* All components that are referenced in the `useValue` value (either directly * 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. * or in a nested array or map) will be added to the `entryComponents` property.
* *
* ### Example * ### Example
* The following example shows how the router can populate the `precompile` * The following example shows how the router can populate the `entryComponents`
* field of an NgModule based on the router configuration which refers * field of an NgModule based on the router configuration which refers
* to components. * to components.
* *
@ -27,7 +27,7 @@ import {StringWrapper, Type, isString, stringify} from '../facade/lang';
* function provideRoutes(routes) { * function provideRoutes(routes) {
* return [ * return [
* {provide: ROUTES, useValue: routes}, * {provide: ROUTES, useValue: routes},
* {provide: ANALYZE_FOR_PRECOMPILE, useValue: routes, multi: true} * {provide: ANALYZE_FOR_ENTRY_COMPONENTS, useValue: routes, multi: true}
* ]; * ];
* } * }
* *
@ -45,7 +45,7 @@ import {StringWrapper, Type, isString, stringify} from '../facade/lang';
* *
* @experimental * @experimental
*/ */
export const ANALYZE_FOR_PRECOMPILE = new OpaqueToken('AnalyzeForPrecompile'); export const ANALYZE_FOR_ENTRY_COMPONENTS = new OpaqueToken('AnalyzeForEntryComponents');
/** /**
* Specifies that a constant attribute value should be injected. * Specifies that a constant attribute value should be injected.

View File

@ -967,58 +967,43 @@ export class ComponentMetadata extends DirectiveMetadata {
interpolation: [string, string]; interpolation: [string, string];
/** /**
* Defines the components that should be precompiled as well when * Defines the components that should be compiled as well when
* this component is defined. For each components listed here, * this component is defined. For each components listed here,
* Angular will create a {@link ComponentFactory ComponentFactory} and store it in the * Angular will create a {@link ComponentFactory ComponentFactory} and store it in the
* {@link ComponentFactoryResolver ComponentFactoryResolver}. * {@link ComponentFactoryResolver ComponentFactoryResolver}.
*/ */
precompile: Array<Type|any[]>; entryComponents: Array<Type|any[]>;
constructor({selector, constructor(
inputs, {selector, inputs, outputs, properties, events, host, exportAs, moduleId, providers,
outputs, viewProviders, changeDetection = ChangeDetectionStrategy.Default, queries, templateUrl,
properties, template, styleUrls, styles, animations, directives, pipes, encapsulation, interpolation,
events, /** @deprecated use entryComponents instead! */
host, precompile, entryComponents}: {
exportAs, selector?: string,
moduleId, inputs?: string[],
providers, outputs?: string[],
viewProviders, /** @deprecated */ properties?: string[],
changeDetection = ChangeDetectionStrategy.Default, /** @deprecated */ events?: string[],
queries, host?: {[key: string]: string},
templateUrl, providers?: any[],
template, exportAs?: string,
styleUrls, moduleId?: string,
styles, viewProviders?: any[],
animations, queries?: {[key: string]: any},
directives, changeDetection?: ChangeDetectionStrategy,
pipes, templateUrl?: string,
encapsulation, template?: string,
interpolation, styleUrls?: string[],
precompile}: { styles?: string[],
selector?: string, animations?: AnimationEntryMetadata[],
inputs?: string[], directives?: Array<Type|any[]>,
outputs?: string[], pipes?: Array<Type|any[]>,
/** @deprecated */ properties?: string[], encapsulation?: ViewEncapsulation,
/** @deprecated */ events?: string[], interpolation?: [string, string],
host?: {[key: string]: string}, precompile?: Array<Type|any[]>,
providers?: any[], entryComponents?: Array<Type|any[]>
exportAs?: string, } = {}) {
moduleId?: string,
viewProviders?: any[],
queries?: {[key: string]: any},
changeDetection?: ChangeDetectionStrategy,
templateUrl?: string,
template?: string,
styleUrls?: string[],
styles?: string[],
animations?: AnimationEntryMetadata[],
directives?: Array<Type|any[]>,
pipes?: Array<Type|any[]>,
encapsulation?: ViewEncapsulation,
interpolation?: [string, string],
precompile?: Array<Type|any[]>
} = {}) {
super({ super({
selector: selector, selector: selector,
inputs: inputs, inputs: inputs,
@ -1043,7 +1028,7 @@ export class ComponentMetadata extends DirectiveMetadata {
this.moduleId = moduleId; this.moduleId = moduleId;
this.animations = animations; this.animations = animations;
this.interpolation = interpolation; this.interpolation = interpolation;
this.precompile = precompile; this.entryComponents = precompile ? precompile : entryComponents;
} }
} }

View File

@ -96,25 +96,25 @@ export class NgModuleMetadata extends InjectableMetadata {
exports: Array<Type|any[]>; exports: Array<Type|any[]>;
/** /**
* Defines the components that should be precompiled as well when * Defines the components that should be compiled as well when
* this component is defined. For each components listed here, * this component is defined. For each components listed here,
* Angular will create a {@link ComponentFactory ComponentFactory} and store it in the * Angular will create a {@link ComponentFactory ComponentFactory} and store it in the
* {@link ComponentFactoryResolver ComponentFactoryResolver}. * {@link ComponentFactoryResolver ComponentFactoryResolver}.
*/ */
precompile: Array<Type|any[]>; entryComponents: Array<Type|any[]>;
constructor({providers, declarations, imports, exports, precompile}: { constructor({providers, declarations, imports, exports, entryComponents}: {
providers?: any[], providers?: any[],
declarations?: Array<Type|any[]>, declarations?: Array<Type|any[]>,
imports?: Array<Type|any[]>, imports?: Array<Type|any[]>,
exports?: Array<Type|any[]>, exports?: Array<Type|any[]>,
precompile?: Array<Type|any[]> entryComponents?: Array<Type|any[]>
} = {}) { } = {}) {
super(); super();
this._providers = providers; this._providers = providers;
this.declarations = declarations; this.declarations = declarations;
this.imports = imports; this.imports = imports;
this.exports = exports; this.exports = exports;
this.precompile = precompile; this.entryComponents = entryComponents;
} }
} }

View File

@ -8,7 +8,7 @@
import {AsyncTestCompleter, beforeEach, ddescribe, xdescribe, describe, expect, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal'; import {AsyncTestCompleter, beforeEach, ddescribe, xdescribe, describe, expect, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal';
import {TestComponentBuilder, configureModule} from '@angular/core/testing'; import {TestComponentBuilder, configureModule} from '@angular/core/testing';
import {Component, ComponentFactoryResolver, NoComponentFactoryError, forwardRef, ANALYZE_FOR_PRECOMPILE, ViewMetadata} from '@angular/core'; import {Component, ComponentFactoryResolver, NoComponentFactoryError, forwardRef, ANALYZE_FOR_ENTRY_COMPONENTS, ViewMetadata} from '@angular/core';
import {stringify} from '../../src/facade/lang'; import {stringify} from '../../src/facade/lang';
export function main() { export function main() {
@ -17,7 +17,7 @@ export function main() {
} }
function declareTests({useJit}: {useJit: boolean}) { function declareTests({useJit}: {useJit: boolean}) {
describe('@Component.precompile', function() { describe('@Component.entryComponents', function() {
beforeEach(() => { configureModule({declarations: [MainComp, ChildComp, NestedChildComp]}); }); beforeEach(() => { configureModule({declarations: [MainComp, ChildComp, NestedChildComp]}); });
it('should error if the component was not declared nor imported by the module', it('should error if the component was not declared nor imported by the module',
@ -27,13 +27,13 @@ function declareTests({useJit}: {useJit: boolean}) {
class ChildComp { class ChildComp {
} }
@Component({template: 'comp', precompile: [ChildComp]}) @Component({template: 'comp', entryComponents: [ChildComp]})
class SomeComp { class SomeComp {
} }
expect(() => tcb.createSync(SomeComp)) expect(() => tcb.createSync(SomeComp))
.toThrowError( .toThrowError(
`Component ${stringify(SomeComp)} in NgModule DynamicTestModule uses ${stringify(ChildComp)} via "precompile" but it was neither declared nor imported into the module!`); `Component ${stringify(SomeComp)} in NgModule DynamicTestModule uses ${stringify(ChildComp)} via "entryComponents" but it was neither declared nor imported into the module!`);
})); }));
@ -47,10 +47,10 @@ function declareTests({useJit}: {useJit: boolean}) {
})); }));
it('should resolve ComponentFactories via ANALYZE_FOR_PRECOMPILE', it('should resolve ComponentFactories via ANALYZE_FOR_ENTRY_COMPONENTS',
inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
let compFixture = tcb.createSync(CompWithAnalyzePrecompileProvider); let compFixture = tcb.createSync(CompWithAnalyzeEntryComponentsProvider);
let mainComp: CompWithAnalyzePrecompileProvider = compFixture.componentInstance; let mainComp: CompWithAnalyzeEntryComponentsProvider = compFixture.componentInstance;
let cfr: ComponentFactoryResolver = let cfr: ComponentFactoryResolver =
compFixture.componentRef.injector.get(ComponentFactoryResolver); compFixture.componentRef.injector.get(ComponentFactoryResolver);
expect(cfr.resolveComponentFactory(ChildComp).componentType).toBe(ChildComp); expect(cfr.resolveComponentFactory(ChildComp).componentType).toBe(ChildComp);
@ -97,14 +97,14 @@ class NestedChildComp {
constructor(public cfr: ComponentFactoryResolver) {} constructor(public cfr: ComponentFactoryResolver) {}
} }
@Component({selector: 'child', precompile: [NestedChildComp], template: ''}) @Component({selector: 'child', entryComponents: [NestedChildComp], template: ''})
class ChildComp { class ChildComp {
constructor(public cfr: ComponentFactoryResolver) {} constructor(public cfr: ComponentFactoryResolver) {}
} }
@Component({ @Component({
selector: 'main', selector: 'main',
precompile: [ChildComp], entryComponents: [ChildComp],
template: '', template: '',
}) })
class MainComp { class MainComp {
@ -115,7 +115,7 @@ class MainComp {
selector: 'comp-with-analyze', selector: 'comp-with-analyze',
template: '', template: '',
providers: [{ providers: [{
provide: ANALYZE_FOR_PRECOMPILE, provide: ANALYZE_FOR_ENTRY_COMPONENTS,
multi: true, multi: true,
useValue: [ useValue: [
{a: 'b', component: ChildComp}, {a: 'b', component: ChildComp},
@ -123,5 +123,5 @@ class MainComp {
] ]
}] }]
}) })
class CompWithAnalyzePrecompileProvider { class CompWithAnalyzeEntryComponentsProvider {
} }

View File

@ -9,7 +9,7 @@
import {LowerCasePipe, NgIf} from '@angular/common'; import {LowerCasePipe, NgIf} from '@angular/common';
import {CompilerConfig, NgModuleResolver, ViewResolver} from '@angular/compiler'; import {CompilerConfig, NgModuleResolver, ViewResolver} from '@angular/compiler';
import {MockNgModuleResolver, MockViewResolver} from '@angular/compiler/testing'; import {MockNgModuleResolver, MockViewResolver} from '@angular/compiler/testing';
import {ANALYZE_FOR_PRECOMPILE, Compiler, Component, ComponentFactoryResolver, ComponentRef, ComponentResolver, DebugElement, Directive, Host, HostBinding, Inject, Injectable, Injector, Input, NgModule, NgModuleMetadata, NgModuleRef, OpaqueToken, Optional, Pipe, Provider, ReflectiveInjector, SelfMetadata, SkipSelf, SkipSelfMetadata, ViewMetadata, forwardRef, getDebugNode, provide} from '@angular/core'; import {ANALYZE_FOR_ENTRY_COMPONENTS, Compiler, Component, ComponentFactoryResolver, ComponentRef, ComponentResolver, DebugElement, Directive, Host, HostBinding, Inject, Injectable, Injector, Input, NgModule, NgModuleMetadata, NgModuleRef, OpaqueToken, Optional, Pipe, Provider, ReflectiveInjector, SelfMetadata, SkipSelf, SkipSelfMetadata, ViewMetadata, forwardRef, getDebugNode, provide} from '@angular/core';
import {Console} from '@angular/core/src/console'; import {Console} from '@angular/core/src/console';
import {ComponentFixture, configureCompiler} from '@angular/core/testing'; import {ComponentFixture, configureCompiler} from '@angular/core/testing';
import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal'; import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
@ -164,14 +164,14 @@ function declareTests({useJit}: {useJit: boolean}) {
`Can't export pipe ${stringify(SomePipe)} from ${stringify(SomeModule)} as it was neither declared nor imported!`); `Can't export pipe ${stringify(SomePipe)} from ${stringify(SomeModule)} as it was neither declared nor imported!`);
}); });
it('should error when precompiling a component that was neither declared nor imported', () => { it('should error when using an entryComponent that was neither declared nor imported', () => {
@NgModule({precompile: [SomeComp]}) @NgModule({entryComponents: [SomeComp]})
class SomeModule { class SomeModule {
} }
expect(() => createModule(SomeModule)) expect(() => createModule(SomeModule))
.toThrowError( .toThrowError(
`NgModule ${stringify(SomeModule)} uses ${stringify(SomeComp)} via "precompile" but it was neither declared nor imported!`); `NgModule ${stringify(SomeModule)} uses ${stringify(SomeComp)} via "entryComponents" but it was neither declared nor imported!`);
}); });
it('should error if a directive is declared in more than 1 module', () => { it('should error if a directive is declared in more than 1 module', () => {
@ -238,9 +238,9 @@ function declareTests({useJit}: {useJit: boolean}) {
}); });
describe('precompile', function() { describe('entryComponents', function() {
it('should precompile ComponentFactories in root modules', () => { it('should entryComponents ComponentFactories in root modules', () => {
@NgModule({declarations: [SomeComp], precompile: [SomeComp]}) @NgModule({declarations: [SomeComp], entryComponents: [SomeComp]})
class SomeModule { class SomeModule {
} }
@ -253,11 +253,11 @@ function declareTests({useJit}: {useJit: boolean}) {
.toBe(SomeComp); .toBe(SomeComp);
}); });
it('should precompile ComponentFactories via ANALYZE_FOR_PRECOMPILE', () => { it('should entryComponents ComponentFactories via ANALYZE_FOR_ENTRY_COMPONENTS', () => {
@NgModule({ @NgModule({
declarations: [SomeComp], declarations: [SomeComp],
providers: [{ providers: [{
provide: ANALYZE_FOR_PRECOMPILE, provide: ANALYZE_FOR_ENTRY_COMPONENTS,
multi: true, multi: true,
useValue: [{a: 'b', component: SomeComp}] useValue: [{a: 'b', component: SomeComp}]
}] }]
@ -274,8 +274,8 @@ function declareTests({useJit}: {useJit: boolean}) {
.toBe(SomeComp); .toBe(SomeComp);
}); });
it('should precompile ComponentFactories in imported modules', () => { it('should entryComponents ComponentFactories in imported modules', () => {
@NgModule({declarations: [SomeComp], precompile: [SomeComp]}) @NgModule({declarations: [SomeComp], entryComponents: [SomeComp]})
class SomeImportedModule { class SomeImportedModule {
} }
@ -292,12 +292,12 @@ function declareTests({useJit}: {useJit: boolean}) {
.toBe(SomeComp); .toBe(SomeComp);
}); });
it('should precompile ComponentFactories if the component was imported', () => { it('should entryComponents ComponentFactories if the component was imported', () => {
@NgModule({declarations: [SomeComp], exports: [SomeComp]}) @NgModule({declarations: [SomeComp], exports: [SomeComp]})
class SomeImportedModule { class SomeImportedModule {
} }
@NgModule({imports: [SomeImportedModule], precompile: [SomeComp]}) @NgModule({imports: [SomeImportedModule], entryComponents: [SomeComp]})
class SomeModule { class SomeModule {
} }
@ -317,7 +317,7 @@ function declareTests({useJit}: {useJit: boolean}) {
it('should be supported in root modules', () => { it('should be supported in root modules', () => {
@NgModule({ @NgModule({
declarations: [CompUsingModuleDirectiveAndPipe, SomeDirective, SomePipe], declarations: [CompUsingModuleDirectiveAndPipe, SomeDirective, SomePipe],
precompile: [CompUsingModuleDirectiveAndPipe] entryComponents: [CompUsingModuleDirectiveAndPipe]
}) })
class SomeModule { class SomeModule {
} }
@ -331,7 +331,7 @@ function declareTests({useJit}: {useJit: boolean}) {
it('should be supported in imported modules', () => { it('should be supported in imported modules', () => {
@NgModule({ @NgModule({
declarations: [CompUsingModuleDirectiveAndPipe, SomeDirective, SomePipe], declarations: [CompUsingModuleDirectiveAndPipe, SomeDirective, SomePipe],
precompile: [CompUsingModuleDirectiveAndPipe] entryComponents: [CompUsingModuleDirectiveAndPipe]
}) })
class SomeImportedModule { class SomeImportedModule {
} }
@ -360,7 +360,7 @@ function declareTests({useJit}: {useJit: boolean}) {
ParentCompUsingModuleDirectiveAndPipe, CompUsingModuleDirectiveAndPipe, SomeDirective, ParentCompUsingModuleDirectiveAndPipe, CompUsingModuleDirectiveAndPipe, SomeDirective,
SomePipe SomePipe
], ],
precompile: [ParentCompUsingModuleDirectiveAndPipe] entryComponents: [ParentCompUsingModuleDirectiveAndPipe]
}) })
class SomeModule { class SomeModule {
} }
@ -383,7 +383,7 @@ function declareTests({useJit}: {useJit: boolean}) {
@NgModule({ @NgModule({
declarations: [ParentCompUsingModuleDirectiveAndPipe], declarations: [ParentCompUsingModuleDirectiveAndPipe],
precompile: [ParentCompUsingModuleDirectiveAndPipe] entryComponents: [ParentCompUsingModuleDirectiveAndPipe]
}) })
class SomeModule { class SomeModule {
} }
@ -415,7 +415,7 @@ function declareTests({useJit}: {useJit: boolean}) {
@NgModule({ @NgModule({
declarations: [ParentCompUsingModuleDirectiveAndPipe], declarations: [ParentCompUsingModuleDirectiveAndPipe],
imports: [SomeImportedModule], imports: [SomeImportedModule],
precompile: [ParentCompUsingModuleDirectiveAndPipe] entryComponents: [ParentCompUsingModuleDirectiveAndPipe]
}) })
class SomeModule { class SomeModule {
} }
@ -437,7 +437,7 @@ function declareTests({useJit}: {useJit: boolean}) {
@NgModule({ @NgModule({
declarations: [CompUsingModuleDirectiveAndPipe], declarations: [CompUsingModuleDirectiveAndPipe],
imports: [SomeImportedModule], imports: [SomeImportedModule],
precompile: [CompUsingModuleDirectiveAndPipe] entryComponents: [CompUsingModuleDirectiveAndPipe]
}) })
class SomeModule { class SomeModule {
} }
@ -461,7 +461,7 @@ function declareTests({useJit}: {useJit: boolean}) {
@NgModule({ @NgModule({
declarations: [CompUsingModuleDirectiveAndPipe], declarations: [CompUsingModuleDirectiveAndPipe],
imports: [SomeImportedModule], imports: [SomeImportedModule],
precompile: [CompUsingModuleDirectiveAndPipe] entryComponents: [CompUsingModuleDirectiveAndPipe]
}) })
class SomeModule { class SomeModule {
} }
@ -484,7 +484,7 @@ function declareTests({useJit}: {useJit: boolean}) {
@NgModule({ @NgModule({
declarations: [CompUsingModuleDirectiveAndPipe], declarations: [CompUsingModuleDirectiveAndPipe],
imports: [SomeImportedModule], imports: [SomeImportedModule],
precompile: [CompUsingModuleDirectiveAndPipe] entryComponents: [CompUsingModuleDirectiveAndPipe]
}) })
class SomeModule { class SomeModule {
} }
@ -505,7 +505,7 @@ function declareTests({useJit}: {useJit: boolean}) {
@NgModule({ @NgModule({
declarations: [CompUsingModuleDirectiveAndPipe], declarations: [CompUsingModuleDirectiveAndPipe],
imports: [SomeImportedModule], imports: [SomeImportedModule],
precompile: [CompUsingModuleDirectiveAndPipe] entryComponents: [CompUsingModuleDirectiveAndPipe]
}) })
class SomeModule { class SomeModule {
} }
@ -524,7 +524,7 @@ function declareTests({useJit}: {useJit: boolean}) {
@NgModule({ @NgModule({
declarations: [CompUsingModuleDirectiveAndPipe, SomePipe], declarations: [CompUsingModuleDirectiveAndPipe, SomePipe],
imports: [SomeImportedModule], imports: [SomeImportedModule],
precompile: [CompUsingModuleDirectiveAndPipe] entryComponents: [CompUsingModuleDirectiveAndPipe]
}) })
class SomeModule { class SomeModule {
} }

View File

@ -30,7 +30,7 @@ export class TestBed implements Injector {
private _providers: Array<Type|Provider|any[]|any> = []; private _providers: Array<Type|Provider|any[]|any> = [];
private _declarations: Array<Type|any[]|any> = []; private _declarations: Array<Type|any[]|any> = [];
private _imports: Array<Type|any[]|any> = []; private _imports: Array<Type|any[]|any> = [];
private _precompile: Array<Type|any[]|any> = []; private _entryComponents: Array<Type|any[]|any> = [];
reset() { reset() {
this._compiler = null; this._compiler = null;
@ -40,7 +40,7 @@ export class TestBed implements Injector {
this._providers = []; this._providers = [];
this._declarations = []; this._declarations = [];
this._imports = []; this._imports = [];
this._precompile = []; this._entryComponents = [];
this._instantiated = false; this._instantiated = false;
} }
@ -56,7 +56,8 @@ export class TestBed implements Injector {
} }
configureModule( configureModule(
moduleDef: {providers?: any[], declarations?: any[], imports?: any[], precompile?: any[]}) { moduleDef:
{providers?: any[], declarations?: any[], imports?: any[], entryComponents?: any[]}) {
if (this._instantiated) { if (this._instantiated) {
throw new BaseException('Cannot add configuration after test injector is instantiated'); throw new BaseException('Cannot add configuration after test injector is instantiated');
} }
@ -69,16 +70,16 @@ export class TestBed implements Injector {
if (moduleDef.imports) { if (moduleDef.imports) {
this._imports = ListWrapper.concat(this._imports, moduleDef.imports); this._imports = ListWrapper.concat(this._imports, moduleDef.imports);
} }
if (moduleDef.precompile) { if (moduleDef.entryComponents) {
this._precompile = ListWrapper.concat(this._precompile, moduleDef.precompile); this._entryComponents = ListWrapper.concat(this._entryComponents, moduleDef.entryComponents);
} }
} }
createModuleFactory(): Promise<NgModuleFactory<any>> { createModuleFactory(): Promise<NgModuleFactory<any>> {
if (this._instantiated) { if (this._instantiated) {
throw new BaseException( throw new BaseException(
'Cannot run precompilation when the test NgModule has already been instantiated. ' + 'Cannot compile entryComponents when the test NgModule has already been instantiated. ' +
'Make sure you are not using `inject` before `doAsyncPrecompilation`.'); 'Make sure you are not using `inject` before `doAsyncEntryPointCompilation`.');
} }
if (this._ngModuleFactory) { if (this._ngModuleFactory) {
@ -122,13 +123,13 @@ export class TestBed implements Injector {
const providers = this._providers.concat([{provide: TestBed, useValue: this}]); const providers = this._providers.concat([{provide: TestBed, useValue: this}]);
const declarations = this._declarations; const declarations = this._declarations;
const imports = [this.ngModule, this._imports]; const imports = [this.ngModule, this._imports];
const precompile = this._precompile; const entryComponents = this._entryComponents;
@NgModule({ @NgModule({
providers: providers, providers: providers,
declarations: declarations, declarations: declarations,
imports: imports, imports: imports,
precompile: precompile entryComponents: entryComponents
}) })
class DynamicTestModule { class DynamicTestModule {
} }
@ -258,13 +259,13 @@ export function resetTestEnvironment() {
} }
/** /**
* Run asynchronous precompilation for the test's NgModule. It is necessary to call this function * Compile entryComponents with a `templateUrl` for the test's NgModule.
* if your test is using an NgModule which has precompiled components that require an asynchronous * It is necessary to call this function
* call, such as an XHR. Should be called once before the test case. * as fetching urls is asynchronous.
* *
* @experimental * @experimental
*/ */
export function doAsyncPrecompilation(): Promise<any> { export function doAsyncEntryPointCompilation(): Promise<any> {
let testBed = getTestBed(); let testBed = getTestBed();
return testBed.createModuleFactory(); return testBed.createModuleFactory();
} }
@ -312,8 +313,8 @@ export function inject(tokens: any[], fn: Function): () => any {
} catch (e) { } catch (e) {
if (e instanceof ComponentStillLoadingError) { if (e instanceof ComponentStillLoadingError) {
throw new Error( throw new Error(
`This test module precompiles the component ${stringify(e.compType)} which is using a "templateUrl", but precompilation was never done. ` + `This test module uses the entryComponents ${stringify(e.compType)} which is using a "templateUrl", but they were never compiled. ` +
`Please call "doAsyncPrecompilation" before "inject".`); `Please call "doAsyncEntryPointCompilation" before "inject".`);
} else { } else {
throw e; throw e;
} }
@ -327,9 +328,12 @@ export function inject(tokens: any[], fn: Function): () => any {
* @experimental * @experimental
*/ */
export class InjectSetupWrapper { export class InjectSetupWrapper {
constructor( constructor(private _moduleDef: () => {
private _moduleDef: providers?: any[],
() => {providers?: any[], declarations?: any[], imports?: any[], precompile?: any[]}) {} declarations?: any[],
imports?: any[],
entryComponents?: any[]
}) {}
private _addModule() { private _addModule() {
var moduleDef = this._moduleDef(); var moduleDef = this._moduleDef();
@ -360,7 +364,7 @@ export function withModule(moduleDef: () => {
providers?: any[], providers?: any[],
declarations?: any[], declarations?: any[],
imports?: any[], imports?: any[],
precompile?: any[] entryComponents?: any[]
}) { }) {
return new InjectSetupWrapper(moduleDef); return new InjectSetupWrapper(moduleDef);
} }

View File

@ -50,7 +50,7 @@ export function addProviders(providers: Array<any>): void {
* @stable * @stable
*/ */
export function configureModule( export function configureModule(
moduleDef: {providers?: any[], declarations?: any[], imports?: any[], precompile?: any[]}): moduleDef: {providers?: any[], declarations?: any[], imports?: any[], entryComponents?: any[]}):
void { void {
if (!moduleDef) return; if (!moduleDef) return;
try { try {

View File

@ -106,7 +106,7 @@ export const browserDynamicPlatform = createPlatformFactory(
* ## API (version 2) * ## API (version 2)
* - `appComponentType`: The root component which should act as the application. This is * - `appComponentType`: The root component which should act as the application. This is
* a reference to a `Type` which is annotated with `@Component(...)`. * a reference to a `Type` which is annotated with `@Component(...)`.
* - `providers`, `declarations`, `imports`, `precompile`: Defines the properties * - `providers`, `declarations`, `imports`, `entryComponents`: Defines the properties
* of the dynamically created module that is used to bootstrap the module. * of the dynamically created module that is used to bootstrap the module.
* - to configure the compiler, use the `compilerOptions` parameter. * - to configure the compiler, use the `compilerOptions` parameter.
* *
@ -121,11 +121,11 @@ export function bootstrap<C>(
customProviders?: Array<any /*Type | Provider | any[]*/>): Promise<ComponentRef<C>>; customProviders?: Array<any /*Type | Provider | any[]*/>): Promise<ComponentRef<C>>;
export function bootstrap<C>( export function bootstrap<C>(
appComponentType: ConcreteType<C>, appComponentType: ConcreteType<C>,
{providers, imports, declarations, precompile, compilerOptions}?: { {providers, imports, declarations, entryComponents, compilerOptions}?: {
providers?: Array<any /*Type | Provider | any[]*/>, providers?: Array<any /*Type | Provider | any[]*/>,
declarations?: any[], declarations?: any[],
imports?: any[], imports?: any[],
precompile?: any[], entryComponents?: any[],
compilerOptions?: CompilerOptions compilerOptions?: CompilerOptions
}): Promise<ComponentRef<C>>; }): Promise<ComponentRef<C>>;
export function bootstrap<C>( export function bootstrap<C>(
@ -134,14 +134,14 @@ export function bootstrap<C>(
providers: Array<any /*Type | Provider | any[]*/>, providers: Array<any /*Type | Provider | any[]*/>,
declarations?: any[], declarations?: any[],
imports: any[], imports: any[],
precompile: any[], entryComponents: any[],
compilerOptions: CompilerOptions compilerOptions: CompilerOptions
}): Promise<ComponentRef<C>> { }): Promise<ComponentRef<C>> {
let compilerOptions: CompilerOptions; let compilerOptions: CompilerOptions;
let providers: any[] = []; let providers: any[] = [];
let declarations: any[] = []; let declarations: any[] = [];
let imports: any[] = []; let imports: any[] = [];
let precompile: any[] = []; let entryComponents: any[] = [];
let deprecationMessages: string[] = []; let deprecationMessages: string[] = [];
if (customProvidersOrDynamicModule instanceof Array) { if (customProvidersOrDynamicModule instanceof Array) {
providers = customProvidersOrDynamicModule; providers = customProvidersOrDynamicModule;
@ -153,7 +153,7 @@ export function bootstrap<C>(
providers = normalizeArray(customProvidersOrDynamicModule.providers); providers = normalizeArray(customProvidersOrDynamicModule.providers);
declarations = normalizeArray(customProvidersOrDynamicModule.declarations); declarations = normalizeArray(customProvidersOrDynamicModule.declarations);
imports = normalizeArray(customProvidersOrDynamicModule.imports); imports = normalizeArray(customProvidersOrDynamicModule.imports);
precompile = normalizeArray(customProvidersOrDynamicModule.precompile); entryComponents = normalizeArray(customProvidersOrDynamicModule.entryComponents);
compilerOptions = customProvidersOrDynamicModule.compilerOptions; compilerOptions = customProvidersOrDynamicModule.compilerOptions;
} }
@ -161,7 +161,7 @@ export function bootstrap<C>(
providers: providers, providers: providers,
declarations: declarations.concat([appComponentType]), declarations: declarations.concat([appComponentType]),
imports: [BrowserModule, imports], imports: [BrowserModule, imports],
precompile: precompile.concat([appComponentType]) entryComponents: entryComponents.concat([appComponentType])
}) })
class DynamicModule { class DynamicModule {
} }
@ -218,7 +218,7 @@ export function bootstrapWorkerApp<T>(
providers: customProviders, providers: customProviders,
declarations: declarations, declarations: declarations,
imports: [WorkerAppModule], imports: [WorkerAppModule],
precompile: [appComponentType] entryComponents: [appComponentType]
}) })
class DynamicModule { class DynamicModule {
} }

View File

@ -9,7 +9,7 @@
import {NgIf} from '@angular/common'; import {NgIf} from '@angular/common';
import {CompilerConfig, XHR} from '@angular/compiler'; import {CompilerConfig, XHR} from '@angular/compiler';
import {Component, ComponentFactoryResolver, Directive, Injectable, Input, NgModule, Pipe, ViewMetadata, provide} from '@angular/core'; import {Component, ComponentFactoryResolver, Directive, Injectable, Input, NgModule, Pipe, ViewMetadata, provide} from '@angular/core';
import {TestComponentBuilder, addProviders, async, configureCompiler, configureModule, doAsyncPrecompilation, fakeAsync, inject, tick, withModule, withProviders} from '@angular/core/testing'; import {TestComponentBuilder, addProviders, async, configureCompiler, configureModule, doAsyncEntryPointCompilation, fakeAsync, inject, tick, withModule, withProviders} from '@angular/core/testing';
import {expect} from '@angular/platform-browser/testing/matchers'; import {expect} from '@angular/platform-browser/testing/matchers';
import {stringify} from '../../http/src/facade/lang'; import {stringify} from '../../http/src/facade/lang';
@ -235,7 +235,7 @@ export function main() {
providers: [FancyService], providers: [FancyService],
imports: [SomeLibModule], imports: [SomeLibModule],
declarations: [SomeDirective, SomePipe, CompUsingModuleDirectiveAndPipe], declarations: [SomeDirective, SomePipe, CompUsingModuleDirectiveAndPipe],
precompile: [CompUsingModuleDirectiveAndPipe] entryComponents: [CompUsingModuleDirectiveAndPipe]
}; };
}); });
@ -260,7 +260,7 @@ export function main() {
expect(libModule).toBeAnInstanceOf(SomeLibModule); expect(libModule).toBeAnInstanceOf(SomeLibModule);
})); }));
it('should use set up precompile components', it('should use set up entryComponents components',
inject([ComponentFactoryResolver], (resolver: ComponentFactoryResolver) => { inject([ComponentFactoryResolver], (resolver: ComponentFactoryResolver) => {
expect(resolver.resolveComponentFactory(CompUsingModuleDirectiveAndPipe).componentType) expect(resolver.resolveComponentFactory(CompUsingModuleDirectiveAndPipe).componentType)
.toBe(CompUsingModuleDirectiveAndPipe); .toBe(CompUsingModuleDirectiveAndPipe);
@ -288,7 +288,7 @@ export function main() {
expect(libModule).toBeAnInstanceOf(SomeLibModule); expect(libModule).toBeAnInstanceOf(SomeLibModule);
})); }));
it('should use set up precompile components', it('should use set up entryComponents components',
withModule(() => moduleConfig) withModule(() => moduleConfig)
.inject([ComponentFactoryResolver], (resolver: ComponentFactoryResolver) => { .inject([ComponentFactoryResolver], (resolver: ComponentFactoryResolver) => {
expect( expect(
@ -297,13 +297,14 @@ export function main() {
})); }));
}); });
describe('precompile components with template url', () => { describe('entryComponents components with template url', () => {
beforeEach(async(() => { beforeEach(async(() => {
configureModule({declarations: [CompWithUrlTemplate], precompile: [CompWithUrlTemplate]}); configureModule(
doAsyncPrecompilation(); {declarations: [CompWithUrlTemplate], entryComponents: [CompWithUrlTemplate]});
doAsyncEntryPointCompilation();
})); }));
it('should allow to createSync components with templateUrl after async precompilation', it('should allow to createSync components with templateUrl after explicit async compilation',
inject([TestComponentBuilder], (builder: TestComponentBuilder) => { inject([TestComponentBuilder], (builder: TestComponentBuilder) => {
let fixture = builder.createSync(CompWithUrlTemplate); let fixture = builder.createSync(CompWithUrlTemplate);
expect(fixture.nativeElement).toHaveText('from external template\n'); expect(fixture.nativeElement).toHaveText('from external template\n');
@ -434,14 +435,14 @@ export function main() {
}); });
}); });
describe('precompile', () => { describe('entryComponents', () => {
let xhrGet: jasmine.Spy; let xhrGet: jasmine.Spy;
beforeEach(() => { beforeEach(() => {
xhrGet = jasmine.createSpy('xhrGet').and.returnValue(Promise.resolve('Hello world!')); xhrGet = jasmine.createSpy('xhrGet').and.returnValue(Promise.resolve('Hello world!'));
configureCompiler({providers: [{provide: XHR, useValue: {get: xhrGet}}]}); configureCompiler({providers: [{provide: XHR, useValue: {get: xhrGet}}]});
}); });
it('should report an error for precompile components with templateUrl which never call doAsyncPrecompile', it('should report an error for entryComponents components with templateUrl which never call doAsyncEntryComponents',
() => { () => {
var itPromise = patchJasmineIt(); var itPromise = patchJasmineIt();
@ -451,7 +452,7 @@ export function main() {
withModule(() => { withModule(() => {
return { return {
declarations: [CompWithUrlTemplate], declarations: [CompWithUrlTemplate],
precompile: [CompWithUrlTemplate] entryComponents: [CompWithUrlTemplate]
}; };
}) })
.inject( .inject(
@ -462,8 +463,8 @@ export function main() {
.toBe(CompWithUrlTemplate); .toBe(CompWithUrlTemplate);
}))) })))
.toThrowError( .toThrowError(
`This test module precompiles the component ${stringify(CompWithUrlTemplate)} which is using a "templateUrl", but precompilation was never done. ` + `This test module uses the entryComponents ${stringify(CompWithUrlTemplate)} which is using a "templateUrl", but they were never compiled. ` +
'Please call "doAsyncPrecompilation" before "inject".'); `Please call "doAsyncEntryPointCompilation" before "inject".`);
restoreJasmineIt(); restoreJasmineIt();
}); });

View File

@ -100,7 +100,7 @@ export function serverBootstrap<T>(
providers: customProviders, providers: customProviders,
declarations: declarations, declarations: declarations,
imports: [BrowserModule], imports: [BrowserModule],
precompile: [appComponentType] entryComponents: [appComponentType]
}) })
class DynamicModule { class DynamicModule {
} }

View File

@ -7,7 +7,7 @@
*/ */
import {Location, LocationStrategy, PathLocationStrategy} from '@angular/common'; import {Location, LocationStrategy, PathLocationStrategy} from '@angular/common';
import {ANALYZE_FOR_PRECOMPILE, APP_INITIALIZER, ApplicationRef, ComponentResolver, Injector, NgModuleFactoryLoader, OpaqueToken, SystemJsNgModuleLoader} from '@angular/core'; import {ANALYZE_FOR_ENTRY_COMPONENTS, APP_INITIALIZER, ApplicationRef, ComponentResolver, Injector, NgModuleFactoryLoader, OpaqueToken, SystemJsNgModuleLoader} from '@angular/core';
import {Routes} from './config'; import {Routes} from './config';
import {Router} from './router'; import {Router} from './router';
@ -88,7 +88,7 @@ export function setupRouterInitializer(injector: Injector) {
*/ */
export function provideRouter(routes: Routes, config: ExtraOptions): any[] { export function provideRouter(routes: Routes, config: ExtraOptions): any[] {
return [ return [
{provide: ANALYZE_FOR_PRECOMPILE, multi: true, useValue: routes}, {provide: ANALYZE_FOR_ENTRY_COMPONENTS, multi: true, useValue: routes},
{provide: ROUTES, useExisting: ROUTER_CONFIG}, {provide: ROUTER_CONFIG, useValue: routes}, {provide: ROUTES, useExisting: ROUTER_CONFIG}, {provide: ROUTER_CONFIG, useValue: routes},
{provide: ROUTER_CONFIGURATION, useValue: config}, Location, {provide: ROUTER_CONFIGURATION, useValue: config}, Location,
@ -130,7 +130,7 @@ export function provideRouter(routes: Routes, config: ExtraOptions): any[] {
*/ */
export function provideRoutes(routes: Routes): any { export function provideRoutes(routes: Routes): any {
return [ return [
{provide: ANALYZE_FOR_PRECOMPILE, multi: true, useValue: routes}, {provide: ANALYZE_FOR_ENTRY_COMPONENTS, multi: true, useValue: routes},
{provide: ROUTES, useValue: routes} {provide: ROUTES, useValue: routes}
]; ];
} }

View File

@ -94,9 +94,9 @@ export class RouterOutlet {
if (!(e instanceof NoComponentFactoryError)) throw e; if (!(e instanceof NoComponentFactoryError)) throw e;
const componentName = component ? component.name : null; const componentName = component ? component.name : null;
console.warn( console.warn(
`'${componentName}' not found in precompile array. To ensure all components referred `'${componentName}' not found in entryComponents array. To ensure all components referred
to by the Routes are compiled, you must add '${componentName}' to the to by the Routes are compiled, you must add '${componentName}' to the
'precompile' array of your application component. This will be required in a future 'entryComponents' array of your application component. This will be required in a future
release of the router.`); release of the router.`);
factory = snapshot._resolvedComponentFactory; factory = snapshot._resolvedComponentFactory;
} }

View File

@ -1326,7 +1326,7 @@ describe('Integration', () => {
children: [{path: 'child', component: ChildLazyLoadedComponent}] children: [{path: 'child', component: ChildLazyLoadedComponent}]
}])], }])],
imports: [RouterModuleWithoutProviders], imports: [RouterModuleWithoutProviders],
precompile: [ParentLazyLoadedComponent, ChildLazyLoadedComponent] entryComponents: [ParentLazyLoadedComponent, ChildLazyLoadedComponent]
}) })
class LoadedModule { class LoadedModule {
} }
@ -1359,7 +1359,7 @@ describe('Integration', () => {
} }
@NgModule({ @NgModule({
precompile: [LazyLoadedComponent], entryComponents: [LazyLoadedComponent],
declarations: [LazyLoadedComponent], declarations: [LazyLoadedComponent],
imports: [RouterModuleWithoutProviders], imports: [RouterModuleWithoutProviders],
providers: [ providers: [
@ -1558,7 +1558,7 @@ class RouteCmp {
template: template:
`<div *ngIf="show"><a [routerLink]="['./simple']">link</a></div> <router-outlet></router-outlet>`, `<div *ngIf="show"><a [routerLink]="['./simple']">link</a></div> <router-outlet></router-outlet>`,
directives: ROUTER_DIRECTIVES, directives: ROUTER_DIRECTIVES,
precompile: [BlankCmp, SimpleCmp] entryComponents: [BlankCmp, SimpleCmp]
}) })
class RelativeLinkInIfCmp { class RelativeLinkInIfCmp {
show: boolean = false; show: boolean = false;
@ -1613,7 +1613,7 @@ class ComponentRecordingRoutePathAndUrl {
selector: 'root-cmp', selector: 'root-cmp',
template: `<router-outlet></router-outlet>`, template: `<router-outlet></router-outlet>`,
directives: [ROUTER_DIRECTIVES], directives: [ROUTER_DIRECTIVES],
precompile: [ entryComponents: [
BlankCmp, SimpleCmp, TeamCmp, UserCmp, StringLinkCmp, DummyLinkCmp, AbsoluteLinkCmp, BlankCmp, SimpleCmp, TeamCmp, UserCmp, StringLinkCmp, DummyLinkCmp, AbsoluteLinkCmp,
RelativeLinkCmp, DummyLinkWithParentCmp, LinkWithQueryParamsAndFragment, CollectParamsCmp, RelativeLinkCmp, DummyLinkWithParentCmp, LinkWithQueryParamsAndFragment, CollectParamsCmp,
QueryParamsAndFragmentCmp, StringLinkButtonCmp, WrapperCmp, LinkInNgIf, QueryParamsAndFragmentCmp, StringLinkButtonCmp, WrapperCmp, LinkInNgIf,
@ -1628,7 +1628,7 @@ class RootCmp {
template: template:
`primary [<router-outlet></router-outlet>] right [<router-outlet name="right"></router-outlet>]`, `primary [<router-outlet></router-outlet>] right [<router-outlet name="right"></router-outlet>]`,
directives: [ROUTER_DIRECTIVES], directives: [ROUTER_DIRECTIVES],
precompile: [BlankCmp, SimpleCmp, RouteCmp, UserCmp] entryComponents: [BlankCmp, SimpleCmp, RouteCmp, UserCmp]
}) })
class RootCmpWithTwoOutlets { class RootCmpWithTwoOutlets {
} }

View File

@ -31,7 +31,7 @@ export const ROUTES = [
@NgModule({ @NgModule({
imports: [WorkerAppModule, RouterModule], imports: [WorkerAppModule, RouterModule],
providers: [provideRoutes(ROUTES), WORKER_APP_LOCATION_PROVIDERS, {provide: LocationStrategy, useClass: HashLocationStrategy}], providers: [provideRoutes(ROUTES), WORKER_APP_LOCATION_PROVIDERS, {provide: LocationStrategy, useClass: HashLocationStrategy}],
precompile: [App], entryComponents: [App],
declarations: [App, Start, Contact, About] declarations: [App, Start, Contact, About]
}) })
export class AppModule { export class AppModule {