Dynamic components, DI and reactive abstractions
Learn Dynamic components, DI and reactive abstractions (Module 17 · Advanced Angular, Angular) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
Building UI at runtime Normally the template decides which components appear. Sometimes you only know at runtime (a dashboard with user-chosen widgets, a modal service). Dynamic component rendering creates them in code. A ViewContainerRef is a "parking spot" in the DOM where you can insert components, and the ComponentRef is the "remote control" returned: it gives access to the instance, lets you set inputs and destroy it. Content projection is the opposite direction: the parent hands pieces of markup to the child with <ng-content> (like slots in a card or dialog).