Angular interview question 2024–10 Different techniques to Render Dynamic Components in Angular

Balram Chavan
6 min readJul 21, 2024

Dynamic component rendering is an essential feature in Angular, allowing developers to create flexible and reusable components. This post explores various techniques for rendering dynamic components in Angular, along with their pros and cons, and performance impacts. As a Senior/Staff/Principal Angular developer, it is essential to know different ways to create a component dynamically depending upon the use case.

Table of Contents

  1. Angular CDK Portal
  2. Dynamic Routing
  3. Component Factory Resolver
  4. ViewContainerRef with Embedded Views
  5. Renderer2 for Direct DOM Manipulation
  6. ngIf Structural Directive
  7. ngSwitch Structural Directive
  8. Template Reference Variables
  9. @defer Block
  10. Using Document API for Dynamic Component Creation

1. Angular CDK Portal

Use Case

The Angular CDK (Component Dev Kit) Portal is ideal for rendering dynamic components in flexible and reusable ways, especially when you need to render components in different parts of the DOM.

Pros

  • High flexibility and reusability.
  • Decouples component logic from DOM positioning.

--

--