'Angular createEmbeddedView without TemplateRef
I want to create a structual directive which conditionally renders the given template or a default text
constructor(
private templateRef: TemplateRef<any>,
private viewContainer: ViewContainerRef,
private renderer: Renderer2e) {
}
@Input() set showIfSome(config: any[]) {
this.viewContainer.clear();
if (someCondition) {
const el: HTMLElement = this.renderer.createElement('span');
el.appendChild(this.renderer.createText('default'))
// >>>> how to render this element instead of templateRef?
} else {
this.viewContainer.createEmbeddedView(this.templateRef);
}
}
But i have no idea how to "createEmbeddedView" from a native element. Some ideas?
Thanks Chris
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
