Question presented to candidate:
"We want a reusable <app-callout> that draws a styled frame, while each page decides what goes inside. How does content projection with ng-content work, and what are the gotchas?"
What a strong answer should cover:
- Content projection passes markup written between a component's tags (its content) into a spot in that component's template marked by
<ng-content>. - The projected content is created and owned by the parent: its bindings use the parent's state and update with the parent's change detection.
<ng-content>is a placeholder, not a real element or a directive; it cannot be bound, styled or repeated.- Fallback content (v18+): markup inside
<ng-content>...</ng-content>shows when nothing is projected. - Gotcha: wrapping
<ng-content>in@ifhides content but does not prevent it from being created; useng-template+ngTemplateOutletor@deferfor truly lazy content. - Projected content lands once: two
<ng-content>for the same content means only the last receives it.
Clarifying questions expected:
- "Does the wrapper need several distinct areas (header, body, footer)? That would be multi-slot projection."
- "Should hidden content be created lazily, or is hiding enough?"
Code / implementation expected: Yes β a wrapper component using ng-content, ideally with fallback content.