Angular / Editorial solution guide
Diagnose missing projected content
Trace content projection selectors, template scope and conditional creation before changing component structure.
Read-only knowledge base ยท No public comments
Recognize the symptoms
A card or container renders, but a supplied heading or action is missing or appears in an unexpected slot. The same child may work outside the container.
Record the container template, caller markup and exact component import context in a small reproduction. Avoid assuming that a CSS visibility issue and missing projection have the same cause.
Understand the likely causes
- A selected ng-content placeholder does not match the supplied child, and no unselected placeholder captures unmatched content. A parent may also lack a required standalone component import.
- A conditional wrapper around ng-content may be mistaken for a mechanism that delays instantiation. Projection and conditional template creation have different lifecycles.
1. Locate the missing node
Inspect the rendered DOM and the caller template with synthetic content. If the child exists but is hidden, examine styles and accessible visibility separately. If the node was never projected, list each ng-content selector in the container and compare it with the supplied element. Include unmatched text and an interactive child in the reproduction so the test covers the intended contract.
2. Repair the slot contract
Align the caller markup with the documented selector, or add an unselected placeholder when the container is intended to accept other content. Confirm that the owner imports the standalone container and any components used in its own template. Do not add a broad schema to silence an unresolved component diagnostic; identify the missing dependency in the correct template scope.
3. Separate conditional creation
Angular processes ng-content as a projection placeholder. Hiding or conditionally wrapping that placeholder is not a reliable way to defer instantiation of its projected content. When creation itself must be conditional, use a suitable template fragment and an explicit creation condition. Verify setup and cleanup of a controlled child when the condition changes, instead of checking only whether pixels are visible.
4. Verify the repair
Render matching, unmatched and empty content cases, then activate a projected control with the keyboard and verify its event reaches the owner. Check the heading hierarchy and accessible names in the complete page. Repeat the original failure and confirm that unrelated content has not moved into a different slot. Retain the reduced template as a regression test for the documented component contract.
Verify the fix
The intended content appears in the correct slot, unrelated content is handled according to the contract, and interactive children remain reachable and functional. Conditional content is created and destroyed only as intended.
Keep it from recurring
- Document slot selectors, fallback behavior, required imports and ownership. Include matching, unmatched and empty content as well as keyboard interaction in component tests.