Single-Slot Content Projection
Project content with ng-content.
Single-Slot Content Projection is a free Angular Academy lesson on CoddyKit. This is lesson 1 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Angular Academy learning path, and your progress syncs across the web and the CoddyKit app. The Angular Academy course includes 4 lessons in total.
What Is Content Projection?
Content projection lets a component receive markup from its parent and render it inside its own template. It is Angular's equivalent of "slots" in web components.
The parent writes content between the component's tags, and the component decides where that content appears.
Why You Need It
Reusable wrappers like cards, dialogs, and panels do not know their content ahead of time. Content projection makes them flexible containers.
- Build a card once, fill it with anything
- Keep layout logic in the component
- Keep content in the consumer
The ng-content Element
The <ng-content> element marks the spot where projected content is placed. A single-slot setup uses exactly one <ng-content> with no select attribute.
@Component({
selector: 'app-card',
template: '<div class="card"><ng-content></ng-content></div>'
})
export class CardComponent {}Using the Component
Whatever the parent places between the component tags is projected into the slot.
<app-card>
<h2>Hello</h2>
<p>This text is projected into the card.</p>
</app-card>Single Slot = One Outlet
With a single unnamed slot, all projected nodes go into the one <ng-content>. There is no filtering; order is preserved exactly as the parent wrote it.
Default Content
You can place fallback markup inside <ng-content>. Modern Angular renders this default content only when the consumer projects nothing into that slot.
<div class="card">
<ng-content>No content provided.</ng-content>
</div>Styling Projected Content
Projected content belongs to the parent's view, so it is styled by the parent's styles, not the card's. To reach projected nodes from the card, use ::ng-deep sparingly or rely on global styles.
Content vs View
Angular distinguishes content children (projected in) from view children (declared in the template). This matters for queries like contentChild vs viewChild.
icon = contentChild(IconComponent);Lifecycle: ngAfterContentInit
Projected content is available after ngAfterContentInit() runs. Use it (or ngAfterContentChecked) to safely read content children.
ngAfterContentInit() {
console.log('Projected content ready');
}A Real Panel Example
Here is a complete reusable panel. The consumer fully controls the inside; the panel controls the shell.
@Component({
selector: 'app-panel',
template: '<section class="panel"><ng-content></ng-content></section>',
styles: ['.panel { border: 1px solid #ccc; padding: 16px; }']
})
export class PanelComponent {}Common Mistake
Placing the same unnamed <ng-content> twice does not duplicate content. Angular only projects into the last matching slot. Use multi-slot projection if you need multiple regions.
Quick Check
Test your understanding of single-slot projection.
Recap
You learned that content projection uses <ng-content> to render parent-supplied markup inside a component. Single-slot projection uses one unnamed outlet, projected content belongs to the parent view, and it becomes available in ngAfterContentInit.
Learn HTML with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 38
- Lessons
- 144
Frequently Asked Questions
Is the “Single-Slot Content Projection” lesson free?
Yes — any 3 lessons of the Angular Academy learning path, including “Single-Slot Content Projection”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Angular Academy course includes 4 lessons in total.
What will I learn in “Single-Slot Content Projection”?
Project content with ng-content. You practise Angular Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Angular Academy?
No prior experience is required. Angular Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 4.
How long does the “Single-Slot Content Projection” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Angular Academy lesson?
Yes. Every Angular Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Single-Slot Content Projection
- Multi-Slot Projection with select
- ng-template and ng-container
- TemplateRef and ViewContainerRef