How does content projection (ng-content) work?

Angular components and templates · Freshers and experienced

Model answer

Content projection lets a parent place its own markup inside a child component. The child template has <ng-content></ng-content> where the content should appear. For example, a card component can wrap any text or elements in a styled box.

You can have several slots with a select attribute, such as <ng-content select="[card-title]">, and the parent marks elements to go in each one. It makes reusable layout components like cards, dialogs and tabs.

Learn this topic

Angular Tutorial: Beginner to Advanced .

Sign in to add your own answer.

More questions