Skip to content

Instantly share code, notes, and snippets.

@MarkTechson
Created November 3, 2021 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarkTechson/19b53a851dc746dadf247eec7d089fdd to your computer and use it in GitHub Desktop.
Save MarkTechson/19b53a851dc746dadf247eec7d089fdd to your computer and use it in GitHub Desktop.
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