Angular 2: How to pass down a template through a component property?
Though this question is very old, there are much better solutions available. There is no need to pass a string as a template - that is very limiting. You can create an element and get its 'TemplateRef' and send that to a component which takes TemplateRef as input. A component can take any number of TemplateRefs as input actually, and you can inject those templates in any number of places.
Note that the 'template' element is deprecated, and the 'ng-template' element should be used in all cases.
So, in a parent component -
<ng-template #thisTemplate>You Can put anything here, including other components</ng-template>
<tab [template]="thisTemplate"></tab>
Then in the tabs component from the OP
import { Component, Input, TemplateRef, ViewChild, ViewContainerRef } from '@angular/core'
.... somehwere in its template ....
<div #viewcontainer></div>
Down in the component :
@ViewChild('viewcontainer',{read:ViewContainerRef}) viewcontainer : ViewContainerRef;
@Input() template : TemplateRef<any>;
ngAfterViewInit() {
this.viewcontainer.createEmbeddedView(this.template);
}