Swiftorial Logo
Home
Swift Lessons
AI Tools
Learn More
Career
Resources

Angular FAQ: Top Questions

44. What is dynamic component loading in Angular?

Dynamic component loading allows components to be instantiated at runtime using ViewContainerRef and ComponentFactoryResolver.


@ViewChild('container', { read: ViewContainerRef }) container: ViewContainerRef;

loadComponent() {
  const factory = this.resolver.resolveComponentFactory(MyComponent);
  this.container.createComponent(factory);
}
        

Useful for plugins, modal dialogs, and runtime-generated UIs.