diff --git a/modules/@angular/compiler/src/runtime_compiler.ts b/modules/@angular/compiler/src/runtime_compiler.ts index f2db5c07db..1c810fdcc7 100644 --- a/modules/@angular/compiler/src/runtime_compiler.ts +++ b/modules/@angular/compiler/src/runtime_compiler.ts @@ -62,7 +62,7 @@ export class RuntimeCompiler implements ComponentResolver { compMeta.selector, compiledTemplate.viewFactory, componentType)); } - clearCache() { + clearCache(): void { this._styleCache.clear(); this._compiledTemplateCache.clear(); this._compiledTemplateDone.clear(); diff --git a/modules/@angular/core/src/linker.ts b/modules/@angular/core/src/linker.ts index b95e337a6b..9e0cc7c39e 100644 --- a/modules/@angular/core/src/linker.ts +++ b/modules/@angular/core/src/linker.ts @@ -5,7 +5,7 @@ export {DynamicComponentLoader} from './linker/dynamic_component_loader'; export {ElementRef} from './linker/element_ref'; export {ExpressionChangedAfterItHasBeenCheckedException} from './linker/exceptions'; export {QueryList} from './linker/query_list'; -export {SystemJsComponentResolver} from './linker/systemjs_component_resolver'; +export {SystemJsCmpFactoryResolver, SystemJsComponentResolver} from './linker/systemjs_component_resolver'; export {TemplateRef} from './linker/template_ref'; export {ViewContainerRef} from './linker/view_container_ref'; export {EmbeddedViewRef, ViewRef} from './linker/view_ref'; diff --git a/modules/@angular/core/src/linker/component_resolver.ts b/modules/@angular/core/src/linker/component_resolver.ts index 933c96d422..8e4dfa8e4a 100644 --- a/modules/@angular/core/src/linker/component_resolver.ts +++ b/modules/@angular/core/src/linker/component_resolver.ts @@ -14,7 +14,7 @@ import {ComponentFactory} from './component_factory'; */ export abstract class ComponentResolver { abstract resolveComponent(component: Type|string): Promise>; - abstract clearCache(): any /** TODO #9100 */; + abstract clearCache(): void; } function _isComponentFactory(type: any): boolean { @@ -37,5 +37,6 @@ export class ReflectorComponentResolver extends ComponentResolver { } return PromiseWrapper.resolve(componentFactory); } + clearCache() {} } diff --git a/modules/@angular/core/src/linker/systemjs_component_resolver.ts b/modules/@angular/core/src/linker/systemjs_component_resolver.ts index aa5fc19c2e..1f128e21a5 100644 --- a/modules/@angular/core/src/linker/systemjs_component_resolver.ts +++ b/modules/@angular/core/src/linker/systemjs_component_resolver.ts @@ -3,6 +3,7 @@ import {Type, global, isString} from '../facade/lang'; import {ComponentFactory} from './component_factory'; import {ComponentResolver} from './component_resolver'; +const _SEPARATOR = '#'; /** * Component resolver that can load components lazily @@ -13,13 +14,42 @@ export class SystemJsComponentResolver implements ComponentResolver { resolveComponent(componentType: string|Type): Promise> { if (isString(componentType)) { + let [module, component] = componentType.split(_SEPARATOR); + + if (component === void(0)) { + // Use the default export when no component is specified + component = 'default'; + } + return (global) - .System.import(componentType) - .then((module: any /** TODO #9100 */) => this._resolver.resolveComponent(module.default)); - } else { - return this._resolver.resolveComponent(componentType); + .System.import(module) + .then((module: any) => this._resolver.resolveComponent(module[component])); } + + return this._resolver.resolveComponent(componentType); } - clearCache() {} + clearCache(): void {} +} + +const FACTORY_MODULE_SUFFIX = '.ngfactory'; +const FACTORY_CLASS_SUFFIX = 'NgFactory'; + +/** + * Component resolver that can load component factories lazily + * @experimental + */ +export class SystemJsCmpFactoryResolver implements ComponentResolver { + resolveComponent(componentType: string|Type): Promise> { + if (isString(componentType)) { + let [module, factory] = componentType.split(_SEPARATOR); + return (global) + .System.import(module + FACTORY_MODULE_SUFFIX) + .then((module: any) => module[factory + FACTORY_CLASS_SUFFIX]); + } + + return Promise.resolve(null); + } + + clearCache(): void {} } diff --git a/modules/@angular/facade/src/lang.ts b/modules/@angular/facade/src/lang.ts index f1ae545d49..b6c752165b 100644 --- a/modules/@angular/facade/src/lang.ts +++ b/modules/@angular/facade/src/lang.ts @@ -128,7 +128,7 @@ export function isNumber(obj: any): boolean { return typeof obj === 'number'; } -export function isString(obj: any): boolean { +export function isString(obj: any): obj is String { return typeof obj === 'string'; } diff --git a/tools/public_api_guard/public_api_spec.ts b/tools/public_api_guard/public_api_spec.ts index ab4d92adeb..8490b3d600 100644 --- a/tools/public_api_guard/public_api_spec.ts +++ b/tools/public_api_guard/public_api_spec.ts @@ -161,7 +161,7 @@ const CORE = [ 'ComponentRef.onDestroy(callback:Function):void', 'ComponentRef', 'ComponentResolver', - 'ComponentResolver.clearCache():any', + 'ComponentResolver.clearCache():void', 'ComponentResolver.resolveComponent(component:Type|string):Promise>', 'const APP_ID:any', 'const APP_INITIALIZER:any', @@ -512,8 +512,11 @@ const CORE = [ 'SkipSelfMetadataFactory', 'state(stateNameExpr:string, styles:AnimationStyleMetadata):AnimationStateDeclarationMetadata', 'style(tokens:string|{[key:string]:string|number}|Array):AnimationStyleMetadata', + 'SystemJsCmpFactoryResolver', + 'SystemJsCmpFactoryResolver.clearCache():void', + 'SystemJsCmpFactoryResolver.resolveComponent(componentType:string|Type):Promise>', 'SystemJsComponentResolver', - 'SystemJsComponentResolver.clearCache():any', + 'SystemJsComponentResolver.clearCache():void', 'SystemJsComponentResolver.constructor(_resolver:ComponentResolver)', 'SystemJsComponentResolver.resolveComponent(componentType:string|Type):Promise>', 'TemplateRef.createEmbeddedView(context:C):EmbeddedViewRef', @@ -1356,7 +1359,7 @@ const COMPILER = [ 'RenderTypes.renderNode:CompileIdentifierMetadata', 'RenderTypes.renderText:CompileIdentifierMetadata', 'RuntimeCompiler', - 'RuntimeCompiler.clearCache():any', + 'RuntimeCompiler.clearCache():void', 'RuntimeCompiler.constructor(_metadataResolver:CompileMetadataResolver, _templateNormalizer:DirectiveNormalizer, _templateParser:TemplateParser, _styleCompiler:StyleCompiler, _viewCompiler:ViewCompiler, _xhr:XHR, _genConfig:CompilerConfig)', 'RuntimeCompiler.resolveComponent(component:Type|string):Promise>', 'SourceModule',