Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk4 min

Content Projection with ng-content in Angular: Slots, Fallbacks, and Limits

Angular’s ng-content places parent-supplied markup into reusable component templates. Learn slot selection, fallback content, ngProjectAs, and important rendering limits.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Angular content projection lets a reusable component place markup supplied by its parent into chosen locations in the component template. A plain <ng-content> creates a default slot; add select when the component needs named locations. The important boundary is ownership: projected markup remains the parent’s content, even when it appears inside the receiving component.

How a default ng-content slot works

<ng-content> is a compile-time placeholder, not a DOM element or Angular component. Angular compiles it as the insertion location for child content supplied on the receiving component’s host. For example, the reusable component can provide a frame:

As an Amazon Associate I earn from qualifying purchases.

<section class="notice">
  <ng-content></ng-content>
</section>

A parent then supplies the content:

<app-notice>
  Your changes have been saved.
</app-notice>

The supplied text is projected into the placeholder location. The component controls the surrounding structure; the parent supplies the inner markup. See Angular’s content projection guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How to route content into multiple ng-content slots

Use select to match child elements to specific locations. Angular’s API reference supports tag-name, attribute, CSS-class, and :not selectors.

<section class="card">
  <ng-content select="card-title">Untitled</ng-content>
  <div class="divider"></div>
  <ng-content select="card-body">No body provided.</ng-content>
</section>

The parent supplies elements that match those selectors:

<custom-card>
  <card-title>Account</card-title>
  <card-body>Settings and profile</card-body>
</custom-card>

Angular places each matching element in its corresponding slot. If some children should go wherever they are not specifically matched, include one unselected <ng-content> as a default slot. Without a default slot, unmatched children are not rendered into the component’s DOM. See the ng-content API reference.

What fallback content and ngProjectAs do

Content written inside a slot is fallback content. Angular uses it when no supplied child matches that slot. For example, the card above displays “Untitled” if the caller does not provide a matching card-title.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When the parent’s element has a different tag but should match a slot, use ngProjectAs to provide a static selector alias:

<custom-card>
  <h3 ngProjectAs="card-title">Account</h3>
  <card-body>Settings and profile</card-body>
</custom-card>

The heading is treated as matching card-title for projection. The alias is static; it cannot be dynamically bound. The Angular API reference documents selector matching, fallback, and aliases.

When content projection is the right choice

Choose the implementation based on whether the receiving component needs fixed layout slots, conditional creation, runtime-selected component types, or active management of its children.

Need Approach Key constraint
Place ordinary parent markup in one location One default <ng-content> All supplied content goes to that location.
Route child elements to defined locations Multiple <ng-content select="…"> slots Unmatched content needs an unselected default slot or it is not rendered.
Render supplied content only under a runtime condition Template fragments Do not make an <ng-content> placeholder conditional.
Choose a component at runtime and supply its content Angular’s programmatic rendering APIs, such as ngComponentOutletContent Hydration does not support projectable nodes created through native DOM APIs.
Manage projected children for focus, keyboard navigation, or ARIA behavior Use the library component’s documented child-management pattern Arbitrary wrapper layers may not work with components that query and manage their children.

For dynamic components, Angular documents passing content through programmatic rendering. Its hydration error reference notes that native-DOM-created projectable nodes are unsupported and mentions ngSkipHydration as a possible workaround: NG0503.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why projected content should not be wrapped in control flow

Do not put <ng-content> inside @if, @for, or @switch to try to create or destroy projected content conditionally. Angular processes the placeholder at build time and creates projected nodes even when the placeholder is hidden. Use template fragments when the content itself must be conditionally rendered. Angular explains this limitation in its content projection guide.

There is a separate matching pitfall when a control-flow block has multiple root nodes: Angular may not match the intended child to a selected slot. The NG8011 error reference recommends putting ngProjectAs on a single-root ng-container, or splitting the content across blocks so each has one projectable root.

Who owns projected content—and what that means

Projection changes where parent-supplied markup appears, not who owns it. Angular checks projected content with the declaring parent, and dependencies used by that content resolve from the parent’s injector context. The receiving component’s viewProviders are not visible to projected content. This follows Angular’s content projection and hierarchical dependency injection guidance.

Also, <ng-content> is compile-time syntax rather than a runtime element. It is not a DOM node on which to attach directives, styling, or arbitrary attributes. Put layout and styling on real elements around the placeholder, and apply behavior to the projected elements where they are declared.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Testing projected content in component harnesses

If a test needs to find a component harness inside supplied child content, scope the harness loader to the projected-content container. Angular’s component harness guide describes using a loader rooted at that container so searches are limited to the relevant projected subtree.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.