Getting content of dynamic templates in component
问题 Here is the template: <button (click)="loadTemplate()">Load Template</button> <ng-template #tmpl let-name> <h2>hello</h2> <h2>{{name}}</h2> </ng-template> Here is the component: export class AppComponent { @ViewChild("tmpl", { read: TemplateRef, static: false }) tmpl: TemplateRef<any>; loadTemplate() { const viewRef = this.tmpl.createEmbeddedView({ $implicit: "angular" }) alert('content for static h2 element: ' + viewRef.rootNodes[0].textContent) alert('content for dynamic h2 element: ' +