Angular / Basic / Lesson 7
Content projection and container components
Use content projection to compose reusable Angular containers while preserving semantic content and ownership.
On this page
Lesson goals
- Explain the difference between a component view and projected content.
- Compose a standalone container with ng-content.
- Verify content, scope, and accessibility.
- Compose standalone containers with clear projected-content ownership and slot matching.
- Verify semantic content, interaction, conditional creation, and injector scope at the correct boundary.
Choose the container contract
A reusable card may provide visual structure while its caller supplies a heading and body. Content projection lets a component place that supplied markup in its own template. The parent still decides what the content means; a generic container should not assume every caller needs the same heading level. Keep the public contract small and use ordinary HTML semantics.
Define a projection placeholder
The card declares a section and a single ng-content placeholder. Angular processes this placeholder at build time; it is not a real DOM element and cannot be added or modified dynamically. The component needs a compatible Angular host and build configuration. This example is a module fragment rather than a standalone executable application.
import { Component } from "@angular/core";
@Component({
selector: "app-card",
template: `<section><ng-content /></section>`
})
export class CardComponent {}
The placeholder is replaced by the caller’s projected content.
The section provides a container and the placeholder marks where caller content is projected.
Supply semantic content
The parent imports the card into its own standalone template scope and supplies a heading and paragraph. The projected elements remain authored by the parent even though they appear inside the card in the DOM. Inspect the heading hierarchy on the complete page and ensure that styling does not hide required content or focus.
import { Component } from "@angular/core";
import { CardComponent } from "./card.component";
@Component({
selector: "app-root",
imports: [CardComponent],
template: `<app-card><h2>Workshop</h2><p>Read first.</p></app-card>`
})
export class AppComponent {}
Workshop
Read first.
The imported card renders its caller-provided heading and paragraph inside the section.
Handle multiple content slots
A container can use selected placeholders to group different kinds of supplied content and an unselected placeholder for unmatched nodes. Without an unselected placeholder, content that matches no slot does not appear. Document the accepted selectors and test a missing or unmatched slot. Do not conditionally wrap ng-content to defer creating its content; Angular processes projection separately from conditional template fragments.
Verify composition
Render the container with a heading, ordinary text and an interactive child. Check that the projected control remains keyboard accessible and that its event still reaches its owner. Also test an empty card and an unmatched child when using selected slots. If injected dependencies are involved, review the declaration and provider boundaries instead of assuming the rendered DOM position alone determines dependency scope.
Separate the container view from caller content
Content projection lets an Angular component place markup supplied by its caller into locations in the component’s own template. The container owns its wrapper and projection placeholders; the caller authors the projected heading, text, controls, and their expressions. DOM placement inside a card does not mean that the card owns the parent’s state or event handlers. A generic card should not assume that every page needs the same heading level. Let the caller choose a heading appropriate to the surrounding document, and document the container’s semantic responsibility.
A standalone parent must import the container it uses in its own template scope. The container’s template and the projected content still need their respective dependencies. A local TypeScript description can explain the relationship, but only a compiled Angular host can establish that the intended content was projected and its bindings work. The fragments below target Angular 20.3.0 and are non-runnable here; their results are predictions, not claims of compilation or browser execution.
Match slots deliberately
An unselected ng-content placeholder accepts projected content not assigned to a selected placeholder. A container can use select attributes to place a heading region and an action region in separate locations. Document the accepted selectors and what happens to unmatched content. If every placeholder is selected and no unselected placeholder exists, unmatched nodes have no projection location and do not appear. A missing optional slot should have a deliberate fallback or an explicitly empty region, not an assumption that every caller supplied it.
The placeholder is processed by Angular at build time and is not itself a DOM element that can be inserted or altered dynamically. Avoid putting ng-content behind @if to defer creation of projected content; use an appropriate template fragment or another documented design when conditional instantiation is required. A CSS class or attribute used for matching is part of the public composition contract. Keep selectors narrow and test matching, missing, and unmatched cases rather than relying only on a successful happy-path screenshot.
Keep declaration and dependency scope clear
Projected markup is declared in the caller’s template even when it appears within the container’s rendered DOM. Expressions and event handlers in that markup belong to the caller’s declaration context. A projected Save button can call the parent’s save method; the container need not reach into private parent fields. A child component inside projected content must be available in the declaring template’s scope. Do not assume the container’s DOM position alone changes expression ownership or grants a different provider.
Dependency injection in projected content can be more nuanced than a simple visual-parent story. Review the actual declaration, injector hierarchy, and provider configuration for the selected Angular version, especially when viewProviders or component-scoped services are involved. Test the intended instance identity in a real host rather than inventing a universal lookup rule from the rendered DOM. A container can expose an explicit input or output when it genuinely coordinates behavior, but avoid turning projection into a hidden global controller.
Compose accessible content without stealing ownership
Use native headings, lists, links, and buttons in the projected content. A card can provide a section or visual frame while the caller supplies an h2 or h3 consistent with the page hierarchy. Do not assign an accessible role or landmark automatically unless the resulting structure has a meaningful name and purpose. A projected interactive control should retain its accessible name, keyboard behavior, and focus indicator, and its action should reach the component that owns it. Styling the container must not hide required content or focus.
Projection is not a trust or authorization boundary. Angular’s normal text interpolation and any rich-content policy have their own rules, and a server must authorize protected data before delivery. Do not use an unrestricted raw HTML escape hatch merely to make a card flexible. Prefer structured caller-authored elements and document any exceptional rich-content boundary separately. Empty cards, long labels, optional actions, and unmatched nodes are important cases because a wrapper can appear correct visually while its actual semantic contract is incomplete.
Verify slots, interaction, and lifecycle
Create a small parent host that imports the standalone container, supplies a heading, paragraph, and native button, then compile and render it in an isolated Angular fixture. Assert the projected content’s order and accessible name, activate the button, and verify the parent-owned result. For selected slots, test each supported selector, a missing optional slot, and unmatched content both with and without an unselected fallback. Inspect the complete heading hierarchy, not just the card fragment.
Where creation timing matters, test whether projected children are created and cleaned up under the chosen template-fragment design; visual hiding alone is not evidence of deferred creation. Test any injector-sensitive relationship with the actual provider hierarchy. Record Angular version, imports, host template, and what was actually run. A component class or synthetic slot list cannot prove DOM placement, keyboard interaction, or dependency resolution. Keep tests and examples isolated from real services and private data.
20 worked examples
1. Single projection slot
Problem: Place caller-provided text within a standalone section container.
- The card template provides one unselected projection placeholder.
- The parent supplies the paragraph as projected content.
@Component({ selector: "app-card", standalone: true, template: `<section><ng-content /></section>` })
class Card {}
// Parent imports Card and uses: <app-card><p>Read first</p></app-card>
Trace the stated slot and ownership; no Angular or browser execution is claimed.
Expected result: In a configured host, the section contains the paragraph Read first.
Why this result follows: The card template provides one unselected projection placeholder. The parent supplies the paragraph as projected content.
2. Caller chooses heading
Problem: Let a page choose a heading level appropriate to its surrounding outline.
- The caller authors the heading element.
- The container places it without choosing a different heading level.
// Card template: <section><ng-content /></section>
// Parent template:
<app-card><h3>Details</h3><p>Review the plan.</p></app-card>
Trace the stated slot and ownership; no Angular or browser execution is claimed.
Expected result: The intended card content contains an h3 Details followed by the paragraph.
Why this result follows: The caller authors the heading element. The container places it without choosing a different heading level.
3. Projected parent expression
Problem: Read a caller-owned value from markup projected into a container.
- The expression is declared in the parent template.
- The card provides placement rather than owning the message property.
@Component({ selector: "app-card", standalone: true, template: `<section><ng-content /></section>` })
class Card {}
@Component({ selector: "app-parent", standalone: true, imports: [Card], template: `<app-card><p>{{ message }}</p></app-card>` })
class Parent { message = "Ready"; }
Trace the stated slot and ownership; no Angular or browser execution is claimed.
Expected result: The intended projected paragraph reads Ready.
Why this result follows: The expression is declared in the parent template. The card provides placement rather than owning the message property.
4. Projected parent event
Problem: Keep a projected button’s event connected to its declaring owner.
- The click binding is authored in the parent template.
- The parent method updates its own status.
@Component({ selector: "app-card", standalone: true, template: `<section><ng-content /></section>` })
class Card {}
@Component({ selector: "app-parent", standalone: true, imports: [Card], template: `<app-card><button type="button" (click)="save()">Save</button></app-card><p>{{ status }}</p>` })
class Parent { status = "Idle"; save(): void { this.status = "Requested"; } }
Trace the stated slot and ownership; no Angular or browser execution is claimed.
Expected result: Activating the projected Save button leads to Requested in the parent view.
Why this result follows: The click binding is authored in the parent template. The parent method updates its own status.
5. Selected heading slot
Problem: Place a marked heading into a dedicated projection location.
- The heading matches the panel-title selector.
- The unselected placeholder receives the unmatched Body paragraph supplied by the parent.
@Component({ selector: "app-panel", standalone: true, template: `<section><header><ng-content select="[panel-title]" /></header><ng-content /></section>` })
class Panel {}
// Parent: <app-panel><h2 panel-title>Report</h2><p>Body</p></app-panel>
Trace the stated slot and ownership; no Angular or browser execution is claimed.
Expected result: The intended header contains Report and the default slot contains Body.
Why this result follows: The heading matches the panel-title selector. The unselected placeholder receives the unmatched Body paragraph supplied by the parent.
6. Selected action slot
Problem: Place a caller-owned action in a distinct footer region.
- The button matches the selected action placeholder.
- The unselected placeholder receives the unmatched Body paragraph in the main region.
@Component({ selector: "app-panel", standalone: true, template: `<section><ng-content /><footer><ng-content select="[panel-action]" /></footer></section>` })
class Panel {}
// Parent: <app-panel><p>Body</p><button panel-action type="button">Save</button></app-panel>
Trace the stated slot and ownership; no Angular or browser execution is claimed.
Expected result: The intended footer contains the Save button while Body remains in the main slot.
Why this result follows: The button matches the selected action placeholder. The unselected placeholder receives the unmatched Body paragraph in the main region.
7. Unmatched content
Problem: Identify what happens when no projection placeholder accepts a node.
- The only placeholder selects nodes marked panel-title.
- The paragraph has no matching marker and there is no unselected fallback.
@Component({ selector: "app-panel", standalone: true, template: `<section><ng-content select="[panel-title]" /></section>` })
class Panel {}
// Parent: <app-panel><p>Unmatched body</p></app-panel>
Trace the stated slot and ownership; no Angular or browser execution is claimed.
Expected result: The unmatched paragraph has no projection location in this fixture.
Why this result follows: The only placeholder selects nodes marked panel-title. The paragraph has no matching marker and there is no unselected fallback.
8. Unselected fallback
Problem: Provide a location for content that does not match a selected slot.
- The heading matches the selected placeholder.
- The unselected placeholder receives the remaining Body paragraph supplied by the caller.
@Component({ selector: "app-panel", standalone: true, template: `<section><ng-content select="[panel-title]" /><ng-content /></section>` })
class Panel {}
// Parent: <app-panel><h2 panel-title>Title</h2><p>Body</p></app-panel>
Trace the stated slot and ownership; no Angular or browser execution is claimed.
Expected result: The intended section contains Title and Body in the declared slot order.
Why this result follows: The heading matches the selected placeholder. The unselected placeholder receives the remaining Body paragraph supplied by the caller.
9. Missing optional action
Problem: Allow a caller to omit a documented optional action slot.
- The paragraph is unmatched and goes to the default slot.
- No supplied node matches the action selector.
@Component({ selector: "app-panel", standalone: true, template: `<section><ng-content /><footer><ng-content select="[panel-action]" /></footer></section>` })
class Panel {}
// Parent supplies only: <app-panel><p>Body</p></app-panel>
Trace the stated slot and ownership; no Angular or browser execution is claimed.
Expected result: The body is projected and no action node appears in the footer.
Why this result follows: The paragraph is unmatched and goes to the default slot. No supplied node matches the action selector.
10. Parent imports container
Problem: Make a standalone container available in the consuming template.
- Card appears in the parent’s standalone imports.
- The app-card element in the parent template matches the Card component selector.
@Component({ selector: "app-card", standalone: true, template: `<section><ng-content /></section>` })
class Card {}
@Component({ selector: "app-parent", standalone: true, imports: [Card], template: `<app-card><p>Note</p></app-card>` })
class Parent {}
Trace the stated slot and ownership; no Angular or browser execution is claimed.
Expected result: The parent declares Card for its template and supplies Note as content.
Why this result follows: Card appears in the parent’s standalone imports. The app-card element in the parent template matches the Card component selector.
11. Missing container import
Problem: Diagnose a standalone parent that uses a container without declaring it.
- Its template uses the app-card selector.
- The empty imports list does not supply that standalone component.
@Component({ selector: "app-parent", standalone: true, imports: [], template: `<app-card><p>Note</p></app-card>` })
class Parent {}
// Card exists separately with selector app-card.
Trace the stated slot and ownership; no Angular or browser execution is claimed.
Expected result: The shown parent does not declare Card as a template dependency.
Why this result follows: Its template uses the app-card selector. The empty imports list does not supply that standalone component.
12. Placeholder is not a DOM node
Problem: Distinguish the projection marker from the rendered wrapper.
- Angular processes the projection placeholder in the component template.
- The caller’s paragraph occupies its designated location.
@Component({ selector: "app-card", standalone: true, template: `<section><ng-content /></section>` })
class Card {}
// Parent: <app-card><p>Note</p></app-card>
Trace the stated slot and ownership; no Angular or browser execution is claimed.
Expected result: The intended DOM has the section and paragraph, not an ng-content element as a normal rendered node.
Why this result follows: Angular processes the projection placeholder in the component template. The caller’s paragraph occupies its designated location.
13. Empty container
Problem: Predict a single-slot container when the caller supplies no children.
- The card still renders its own wrapper.
- The caller supplies no child nodes for the single projection placeholder.
@Component({ selector: "app-card", standalone: true, template: `<section><ng-content /></section>` })
class Card {}
// Parent: <app-card />
Trace the stated slot and ownership; no Angular or browser execution is claimed.
Expected result: The section is present with no projected child content.
Why this result follows: The card still renders its own wrapper. The caller supplies no child nodes for the single projection placeholder.
14. Native link inside card
Problem: Retain destination semantics for a projected navigation link.
- The caller supplies a native anchor.
- Projection changes placement rather than converting the destination into an action button.
// Card template: <section><ng-content /></section>
// Parent template:
<app-card><a href="/courses">Courses</a></app-card>
Trace the stated slot and ownership; no Angular or browser execution is claimed.
Expected result: The projected Courses element remains a link with href /courses.
Why this result follows: The caller supplies a native anchor. Projection changes placement rather than converting the destination into an action button.
15. Do not defer with ng-content
Problem: Identify an unsupported assumption about conditional creation of projected content.
- ng-content is a build-time projection placeholder.
- Use a documented template-fragment design when conditional instantiation is required.
@Component({ selector: "app-panel", standalone: true, template: `@if (show) { <ng-content /> }` })
class Panel { show = false; }
Trace the stated slot and ownership; no Angular or browser execution is claimed.
Expected result: The fixture must not be used to claim that projected content creation is deferred.
Why this result follows: ng-content is a build-time projection placeholder. Use a documented template-fragment design when conditional instantiation is required.
16. Semantic list content
Problem: Project a caller-authored list without replacing its list semantics.
- The parent supplies the ul and li structure.
- The container provides a section without rewriting the list items.
// Card template: <section><ng-content /></section>
// Parent template:
<app-card><ul><li>Read</li><li>Practice</li></ul></app-card>
Trace the stated slot and ownership; no Angular or browser execution is claimed.
Expected result: The intended card contains a list with Read then Practice.
Why this result follows: The parent supplies the ul and li structure. The container provides a section without rewriting the list items.
17. No authorization by projection
Problem: Separate a client presentation slot from access to private data.
- Selecting displayed content does not remove already delivered fields.
- A real server must authorize and minimize data before delivery.
const delivered = { title: "Report", privateNote: "synthetic" };
const visibleTitle = delivered.title;
Trace the stated slot and ownership; no Angular or browser execution is claimed.
Expected result: The visible title is Report, but the delivered object still contains privateNote.
Why this result follows: Selecting displayed content does not remove already delivered fields. A real server must authorize and minimize data before delivery.
18. Provider scope test plan
Problem: Avoid inferring injection scope solely from the projected DOM position.
- Projected content is declared by the caller.
- Provider and declaration boundaries need verification under the configured Angular host.
const test = { parentProvider: "A", containerProvider: "B", question: "which instance does the projected child resolve?", executed: false };
Trace the stated slot and ownership; no Angular or browser execution is claimed.
Expected result: The fixture requires an actual injector-hierarchy test and records that it was not run.
Why this result follows: Projected content is declared by the caller. Provider and declaration boundaries need verification under the configured Angular host.
19. Conditional fragment plan
Problem: Choose a template-fragment design when creation must be conditional.
- ng-content projection is not a general deferred-instantiation mechanism.
- A suitable template fragment can represent the explicit conditional boundary.
const contract = { requirement: "do not create expensive content until opened", mechanism: "documented template fragment", verify: ["creation", "cleanup"] };
Trace the stated slot and ownership; no Angular or browser execution is claimed.
Expected result: The plan calls for testing creation and cleanup rather than only visual hiding.
Why this result follows: ng-content projection is not a general deferred-instantiation mechanism. A suitable template fragment can represent the explicit conditional boundary.
20. Keyboard interaction plan
Problem: Verify a projected button through the caller’s actual behavior.
- The projected native button should retain its accessible name and keyboard behavior.
- The event binding must still reach the declaring parent in a real host.
const test = { content: "Save button", steps: ["Tab to Save", "activate", "check parent status"], executed: false };
Trace the stated slot and ownership; no Angular or browser execution is claimed.
Expected result: The fixture specifies a keyboard journey and records no execution.
Why this result follows: The projected native button should retain its accessible name and keyboard behavior. The event binding must still reach the declaring parent in a real host.
Common errors and fixes
Projected content is missing.
- Why it happens
- No placeholder matches the supplied node.
- How to fix it
- Add the intended selector or an unselected placeholder.
- Prevent it next time
- Test each documented slot and an unmatched child.
The parent template cannot resolve the card.
- Why it happens
- The standalone parent did not import the component.
- How to fix it
- Import the card into the owning template scope.
- Prevent it next time
- Compile a minimal parent that uses the container.
Conditional projection still creates unwanted content.
- Why it happens
- ng-content is processed as a projection placeholder.
- How to fix it
- Use a template fragment for content that must be created conditionally.
- Prevent it next time
- Test creation and cleanup rather than only visual hiding.
20 practice exercises
1. A card needs caller-provided headings and text. Who owns the heading level?
Show hint
The caller knows the surrounding page’s heading hierarchy.
Show worked solution
The caller chooses a heading appropriate to its page context; the card supplies the container and projection placeholder. Verify the resulting document outline where the card is used.
The caller chooses an appropriate heading level and supplies it as projected content; the card owns its documented container and placeholder. Verify the complete page outline and that styling preserves readable content and focus.
Check your solution
- The caller selects the heading level.
- The rendered page hierarchy is reviewed.
2. Why can an unmatched child disappear from a multi-slot card?
Show hint
Trace whether any placeholder accepts the node.
Show worked solution
Selected placeholders accept matching nodes. If no unselected placeholder exists, unmatched nodes have nowhere to render. Add an appropriate fallback slot or document that the child is unsupported.
A selected placeholder accepts matching nodes. If the paragraph matches none and the container has no unselected placeholder, it has no projection location. Add a documented fallback slot when appropriate or reject that unsupported composition.
Check your solution
- The unmatched node is identified.
- The fallback or unsupported-content policy is explicit.
3. Create a standalone card that places caller content inside a section using one projection placeholder.
Show hint
The container owns the wrapper and the caller owns the supplied nodes.
Show worked solution
Define a standalone component with selector app-card and template <section><ng-content /></section>. The parent imports Card and supplies a heading and paragraph inside <app-card>. Compile and render the host to verify placement; the placeholder itself is not an ordinary DOM element.
Check your solution
- The parent imports and uses the card.
- The supplied content appears inside the section.
4. A caller places an h3 and paragraph inside a card. Who chooses the heading level and why?
Show hint
The surrounding page gives the heading its context.
Show worked solution
The caller chooses h3 or another appropriate level because it owns the content and knows the complete document hierarchy. The card supplies its documented container and projection location. Inspect the rendered page outline rather than assuming every use should have the same heading level.
Check your solution
- The caller owns the heading choice.
- The resulting page hierarchy is checked.
5. A standalone parent uses app-card but its imports array is empty. Identify the missing boundary.
Show hint
The component that declares the template must have its dependency available.
Show worked solution
Import Card into the parent source and include it in the parent’s standalone imports. Confirm that app-card matches the container selector, then compile the actual host. Merely defining Card elsewhere does not make it available to the parent template.
Check your solution
- The consuming parent imports Card.
- The selector matches the used element.
6. A card projects <p>{{ message }}</p> declared by the parent. Which component owns message?
Show hint
Projection changes placement, not the declaration context.
Show worked solution
The parent template owns the expression and supplies message. The card defines where the paragraph appears but should not need a private copy of that state. Update the parent value in a host test and verify the projected text follows the documented binding.
Check your solution
- The parent provides message.
- The card provides the projection location.
7. A projected Save button calls save(). Explain whose method is invoked and what to test.
Show hint
The event binding is declared in the caller’s template.
Show worked solution
The caller’s save method handles the button event when that is where the binding is declared. Test the native button’s accessible name, keyboard activation, and the parent-owned resulting state. The container should not claim that an emitted request already persisted remotely.
Check your solution
- The caller’s handler receives activation.
- The accessible control and parent result are verified.
8. A panel needs a title slot and a default body slot. Describe selectors and expected placement.
Show hint
Use a selected placeholder and an unselected fallback.
Show worked solution
Define <ng-content select="[panel-title]" /> in the title region and an unselected <ng-content /> for remaining content. A marked h2 goes to the title region and an ordinary paragraph goes to the body. Document the marker and test both matching and missing content.
Check your solution
- The marked heading reaches the title slot.
- Unmatched body content reaches the default slot.
9. A multi-slot card has only select="[title]" and receives an ordinary paragraph. Predict the result.
Show hint
No unselected placeholder accepts the unmatched node.
Show worked solution
The paragraph does not appear in a projection location in this fixture because it lacks the title marker and no default slot is defined. Add an appropriate unselected placeholder if body content is supported, or document that it is unsupported. Verify in the actual host.
Check your solution
- The paragraph is identified as unmatched.
- The documented slot policy resolves or rejects it.
10. A panel has an optional action slot but the caller supplies only body text. Define the expected result.
Show hint
A selected slot can legitimately have no matching node.
Show worked solution
The body goes to the unselected placeholder and the action region contains no projected action under the shown contract. Ensure the empty wrapper remains semantically appropriate and does not create a misleading control. Test a second host that supplies the action marker.
Check your solution
- Body content is projected.
- No unsupported action is invented.
11. A developer wraps ng-content in @if to defer creating an expensive child. Explain the limitation.
Show hint
The placeholder is processed as projection, not a general deferred-instantiation switch.
Show worked solution
Use a documented template-fragment or other supported conditional creation design when the child must not be instantiated until needed. Test actual creation and cleanup in a host rather than assuming hidden projected content was never created. Keep the caller and container ownership contract explicit.
Check your solution
- Conditional creation uses an appropriate supported mechanism.
- The test checks creation and cleanup, not only visibility.
12. A projected child injects a service. Can its provider be inferred solely from its visual DOM parent?
Show hint
Declaration and injector boundaries need their own analysis.
Show worked solution
Inspect where the projected child is declared and the configured provider hierarchy for the selected Angular version. Use a component fixture to assert which service instance it receives, especially with viewProviders or nearer overrides. The fact that the node appears inside a card is not sufficient evidence.
Check your solution
- The actual declaration and injector configuration are reviewed.
- The expected instance is verified in a host.
13. A card projects a Courses link. What semantics should remain after projection?
Show hint
A destination should remain a native link with its href.
Show worked solution
Supply <a href="/courses">Courses</a> as caller content and verify that it remains discoverable as a link with the same destination after projection. Test keyboard access and focus styling in the full page. The card should not turn navigation into a click-only div.
Check your solution
- The link retains href /courses.
- Keyboard and focus behavior are checked.
14. A card supplies a section but the parent provides no content. Define an empty-state test.
Show hint
The wrapper can exist even when no child is projected.
Show worked solution
Render <app-card /> and inspect the resulting section under the documented contract. Decide whether an empty section is acceptable or whether the caller must supply content; do not invent a heading or action silently. Test any required-content rule at the appropriate boundary.
Check your solution
- The empty case is exercised explicitly.
- The contract states whether empty content is supported.
15. A container styles projected text but hides the focus outline of a projected button. Explain the defect.
Show hint
Composition must preserve interaction as well as appearance.
Show worked solution
Restore a visible focus indicator and verify the button’s accessible name and keyboard activation in the full page. A visually styled card is not correct if it makes a caller-owned control unusable. Include focus behavior in compatibility review for container style changes.
Check your solution
- Keyboard focus remains visible.
- The projected button remains operable and named.
16. A generic card accepts raw HTML to make projection flexible. Propose a narrower content contract.
Show hint
Structured projected elements do not need an unrestricted raw HTML sink.
Show worked solution
Let callers supply structured headings, paragraphs, and controls through projection. If rich HTML is genuinely required, isolate it behind a separately reviewed sanitization and trust policy. A generic wrapper should not silently grant arbitrary markup insertion to every caller.
Check your solution
- Ordinary content is structured.
- Any raw HTML path has an explicit reviewed boundary.
17. A projected child component is unknown in the caller’s template. Where should its dependency be checked?
Show hint
The caller declares the projected markup.
Show worked solution
Ensure the child component is available in the declaring parent’s template scope as well as the card being imported for its own selector. Compile the parent host and inspect the actual diagnostic. Importing a child only inside the card does not automatically make it available to arbitrary caller markup.
Check your solution
- The declaring parent has the required dependency.
- The host template compiles with the intended child.
18. Two selected slots use markers panel-title and panel-action. Design a host test for both.
Show hint
Supply one matching node for each documented selector.
Show worked solution
Render a marked heading and a marked native button, assert each appears in its intended region, and activate the button to verify its owner’s behavior. Also test a missing action and an unmatched paragraph under the documented fallback policy. Use an isolated Angular host.
Check your solution
- Both selected regions receive the intended nodes.
- Missing and unmatched cases are covered.
19. A card hides a private note visually but the client already received the full record. Explain the trust boundary.
Show hint
Projection and display do not remove delivered data.
Show worked solution
The browser user can inspect data delivered to the client even if the card does not display it. Authorize the request and project only permitted fields on the trusted server before serialization. A container’s slot policy is not an access-control mechanism.
Check your solution
- The server restricts the delivered fields.
- Visual hiding is not treated as authorization.
20. Design a composition test covering projected content, interaction, accessibility, and host teardown.
Show hint
Use a representative parent host and state what it proves.
Show worked solution
Import the card in a parent fixture, project a heading, paragraph, and Save button, and verify order and accessible names. Activate Save by keyboard and assert the parent-owned result; test empty and unmatched slot cases and clean up the host. Record that provider scope or server behavior requires separate evidence.
Check your solution
- Projected content and keyboard interaction are verified.
- The host is cleaned up and evidence limits are explicit.
Key takeaways
- Projected content is supplied by the caller.
- Projection placeholders are processed at build time.
- Test scope, slot matching and accessible composition.
- The caller declares projected content while the container owns its placeholders and wrapper.
- Unmatched content needs an unselected slot or an explicit unsupported policy.
- Projection does not defer creation, authorize data, or establish injector scope by DOM position alone.