2016-04-28 17:50:03 -07:00
|
|
|
import {Directive, Input, ViewContainerRef, ViewRef, TemplateRef} from '@angular/core';
|
|
|
|
import {isPresent} from '../../src/facade/lang';
|
2016-04-11 17:47:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and inserts an embedded view based on a prepared `TemplateRef`.
|
|
|
|
*
|
|
|
|
* ### Syntax
|
|
|
|
* - `<template [ngTemplateOutlet]="templateRefExpression"></template>`
|
2016-05-27 11:24:05 -07:00
|
|
|
*
|
|
|
|
* @experimental
|
2016-04-11 17:47:28 +02:00
|
|
|
*/
|
|
|
|
@Directive({selector: '[ngTemplateOutlet]'})
|
|
|
|
export class NgTemplateOutlet {
|
|
|
|
private _insertedViewRef: ViewRef;
|
|
|
|
|
|
|
|
constructor(private _viewContainerRef: ViewContainerRef) {}
|
|
|
|
|
|
|
|
@Input()
|
2016-04-28 14:00:31 -07:00
|
|
|
set ngTemplateOutlet(templateRef: TemplateRef<Object>) {
|
2016-04-11 17:47:28 +02:00
|
|
|
if (isPresent(this._insertedViewRef)) {
|
|
|
|
this._viewContainerRef.remove(this._viewContainerRef.indexOf(this._insertedViewRef));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isPresent(templateRef)) {
|
|
|
|
this._insertedViewRef = this._viewContainerRef.createEmbeddedView(templateRef);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|