Sitemap
Better Programming

Advice for programmers.

Member-only story

Understanding Content Projection in Angular

3 min readJun 6, 2019

--

Content projection (also known as transclusion) is a way to import HTML content from outside a component and insert that content into the component’s template in a designated spot.

Therefore, using content projection, you can obtain the result shown in the following image.

Press enter or click to view image in full size

Notice that the component works like a mirror. Another more complicated example is the one shown in the following image in which a letter with user data is being configured.

Press enter or click to view image in full size

What is a ng-container?

The Angular ng-container is a grouping element (syntax element) that doesn’t interfere with styles or layout because Angular doesn’t put it in the DOM.

And we can use structural directives with it.

A structural directive changes the DOM layout by adding, removing, or manipulating DOM elements.

Press enter or click to view image in full size

--

--

Carlos Caballero
Carlos Caballero

Written by Carlos Caballero

Hi! My name is Carlos Caballero and I’m PhD. in Computer Science from Málaga, Spain. Teaching developers and degree/master computer science how to be experts!