I am trying to find a way to dynamically construct a template in Angular2. I was thinking templateRef might provide a way to do this. But I could be wrong.
I found an ex
ngForTemplate
is only supported with ngFor
or
not on a plain template. It is an @Input()
on the NgFor directive
Another way to use TemplateRef
If you have a reference to ViewContainerRef
you can use it to "stamp" the template
constructor(private _viewContainer: ViewContainerRef) { }
ngOnInit() {
this.childView = this._viewContainer.createEmbeddedView(this.templ);
this.childView.setLocal('data', this.data);
}