-
Notifications
You must be signed in to change notification settings - Fork 26.5k
Closed
Description
Current behavior
NgTemplateOutlet
does not accept context.
Expected/desired behavior
NgTemplateOutlet
has an additional @Input
that allows attaching local context to EmbeddedViewRef
Other information
After feat(core): introduce template context it is relativly easy to supply a context to the template ref
Should be something like
import {Directive, Input, ViewContainerRef, ViewRef, TemplateRef} from 'angular2/core';
import {isPresent} from 'angular2/src/facade/lang';
/**
* Creates and inserts an embedded view based on a prepared `TemplateRef`.
*
* ### Syntax
* - `<template [ngTemplateOutlet]="templateRefExpression"></template>`
*/
@Directive({selector: '[ngTemplateOutlet]'})
export class NgTemplateOutlet {
private _insertedViewRef: ViewRef;
private _context: Object;
constructor(private _viewContainerRef: ViewContainerRef) {}
@Input()
set ngTemplateOutletContext(context: Object) {
this._context = context;
}
@Input()
set ngTemplateOutlet(templateRef: TemplateRef<Object>) {
if (isPresent(this._insertedViewRef)) {
this._viewContainerRef.remove(this._viewContainerRef.indexOf(this._insertedViewRef));
}
if (isPresent(templateRef)) {
this._insertedViewRef = this._viewContainerRef.createEmbeddedView(templateRef, this._context);
}
}
}
pmowrer, fxck and stalniy
Metadata
Metadata
Assignees
Labels
No labels