Junior From PDF Angular Angular

What is the purpose of ng-content in Angular?

<ng-content> is used for content projection, i.e., to pass custom content into a

component from a parent.

Example:

<!-- alert.component.html -->

<div class="alert-box">

<ng-content></ng-content>

</div>

Usage:

<app-alert>

<p>Warning! Something went wrong.</p>

</app-alert>

Real-Time Example:

Reusable modal or alert components that display different messages using

<ng-content>.

More from Angular Tutorial

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details