refactor(core): don’t store view factory in TemplateRef

Instead, generate `createEmbeddedView`.
This commit is contained in:
Tobias Bosch
2016-11-01 10:29:25 -07:00
committed by vikerman
parent d1035da85c
commit 74ede9aa9b
8 changed files with 54 additions and 20 deletions

View File

@ -17,9 +17,8 @@ import {ViewType} from './view_type';
/**
* An AppElement is created for elements that have a ViewContainerRef,
* a nested component or a <template> element to keep data around
* that is needed for later instantiations.
* An AppElement is created for elements that have a ViewContainerRef
* to keep track of the nested views.
*/
export class AppElement {
public nestedViews: AppView<any>[];

View File

@ -43,15 +43,16 @@ export abstract class TemplateRef<C> {
}
export class TemplateRef_<C> extends TemplateRef<C> {
constructor(private _appElement: AppElement, private _viewFactory: Function) { super(); }
constructor(
private _parentView: AppView<any>, private _nodeIndex: number, private _nativeElement: any) {
super();
}
createEmbeddedView(context: C): EmbeddedViewRef<C> {
var view: AppView<C> = this._viewFactory(
this._appElement.parentView.viewUtils, this._appElement.parentInjector,
this._appElement.parentView, this._appElement.index, this._appElement.nativeElement);
const view = this._parentView.createEmbeddedViewInternal(this._nodeIndex);
view.create(context || <any>{});
return view.ref;
}
get elementRef(): ElementRef { return this._appElement.elementRef; }
get elementRef(): ElementRef { return new ElementRef(this._nativeElement); }
}

View File

@ -88,6 +88,11 @@ export abstract class AppView<T> {
*/
createInternal(rootSelectorOrNode: string|any): ComponentRef<any> { return null; }
/**
* Overwritten by implementations.
*/
createEmbeddedViewInternal(templateNodeIndex: number): AppView<any> { return null; }
init(lastRootNode: any, allNodes: any[], disposables: Function[]) {
this.lastRootNode = lastRootNode;
this.allNodes = allNodes;