Skip to content

Instantly share code, notes, and snippets.

@MarkTechson
Created Nov 3, 2021
Embed
What would you like to do?
Dynamically Create Components
@Directive({})
export class MyDirective {
constructor(private viewContainerRef: ViewContainerRef,
private componentFactoryResolver:
ComponentFactoryResolver) {}
createMyComponent() {
const componentFactory = this.componentFactoryResolver.
resolveComponentFactory(MyComponent);
this.viewContainerRef.createComponent(componentFactory);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment