Hello,
I need a way to define template ref variable to simplify the variable
reference syntax inside a template.
For this I implemented my own directive:
import { Directive, Input, TemplateRef, ViewContainerRef, EmbeddedViewRef }
from '@angular/core';
export class TemplateVarRow {
constructor(public $implicit: any) {
}
}
@Directive({ selector: '[templatevar][templatevarOf]' })
export class TemplateVarDirective {
private view: EmbeddedViewRef<TemplateVarRow>;
constructor(
private templateRef: TemplateRef<TemplateVarRow>,
private viewContainer: ViewContainerRef) {
}
@Input() set templatevarOf(variable: any) {
if(this.view) {
this.viewContainer.remove(0);
}
this.view = this.viewContainer.createEmbeddedView(this.templateRef, new
TemplateVarRow(variable));
}
}
Then I use it in a template:
<div *templatevar="let site of (site$ | async)" class="container">
<p>{{site.name}}</p>
</div>
Is there a way to do similar thing in angular 2 without writing my own
custom directive?
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.