Question presented to candidate:
"We are building a reusable list component, and each team wants rows to look different. How would you use ngTemplateOutlet to let the parent decide what a row looks like, and how does data get into that template?"
What a strong answer should cover:
NgTemplateOutletis a directive from@angular/commonthat renders aTemplateRefat its location as an embedded view.- Data goes in through a context object:
$implicitmaps tolet-x, named keys map tolet-x="key". - Two syntaxes:
*ngTemplateOutlet="tpl; context: ctx"or[ngTemplateOutlet]="tpl" [ngTemplateOutletContext]="ctx", usually on anng-container. - Pattern: a child accepts a
TemplateRefinput (or queries one), and falls back to a default template. - Behaviour: changing the context updates the existing view; changing the template destroys and recreates it.
- Limits:
let-variables are untyped (any) under strict templates unless you add a typed directive;ngTemplateOutletInjectorcontrols which injector the view uses.
Clarifying questions expected:
- "Should the parent pass a template as an input, or project it as content?"
- "Does the row template need access to services from the child or from the parent?"
Code / implementation expected: Yes β a child component rendering a parent-supplied template with a context.