If you’re creating a component library or working on components meant to be as generic and reusable as possible, then content projection should be a major part of your Angular toolkit.
Let’s take the example of a pop-up window/dialog component:
The main idea of content projection is that the parent component (most likely a container component) knows about the current use case of our reusable presentation component and can pass custom HTML to it. Such content is passed in the content section of the component, which is the body of the HTML element – what we have between the opening and the closing tag:
Angular projects that content into the template of the child component. We can set the destination of that projection by using an ng-content
element in the template of the reusable component as follows:
Content projection is like cutting and pasting some content from one component to another. You can see the full code example here on Stackblitz.