How does content projection (ng-content) work?
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
- What are the parts of a component?
- What is data binding? Explain the four types.
- What is the difference between interpolation and property binding?
- How do you pass data from a parent component to a child component?
- How does a child component send data to its parent?
- What is the component lifecycle? Describe the main hooks.