Angular - Advanced PatternsYou want to create a custom structural directive that repeats a template N times. Which approach correctly implements this behavior?ACreate multiple components dynamically instead of using embedded views.BInject TemplateRef and ViewContainerRef, then loop N times calling createEmbeddedView each iteration.CUse a service to generate an array of N elements and bind with *ngFor inside the directive.DUse Renderer2 to clone the element N times manually.Check Answer
Step-by-Step SolutionSolution:Step 1: Understand how to repeat templates in structural directivesRepeating means creating multiple embedded views of the same template.Step 2: Use ViewContainerRef to create views in a loopInject TemplateRef and ViewContainerRef, then loop N times calling createEmbeddedView to render the template multiple times.Final Answer:Inject TemplateRef and ViewContainerRef, then loop N times calling createEmbeddedView each iteration. -> Option BQuick Check:Repeat template = loop createEmbeddedView calls [OK]Quick Trick: Loop createEmbeddedView calls to repeat template N times [OK]Common Mistakes:Using Renderer2 to clone elements (not Angular way)Trying to use *ngFor inside directive templateCreating multiple components unnecessarily
Master "Advanced Patterns" in Angular9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More Angular Quizzes Angular Signals - Signal creation and reading - Quiz 4medium Animations - Keyframe animations - Quiz 2easy Internationalization and Accessibility - ARIA attributes in templates - Quiz 11easy Internationalization and Accessibility - Angular i18n built-in support - Quiz 4medium Performance Optimization - Virtual scrolling for large lists - Quiz 6medium Standalone Components - Standalone pipes and directives - Quiz 2easy State Management - Effects for side effects - Quiz 5medium Testing - Testing HTTP calls with HttpTestingController - Quiz 8hard Testing - TestBed configuration - Quiz 3easy Testing - TestBed configuration - Quiz 8hard