Projecting multiple sections

It is possible to include more than a single pair of ng-content tags. However, since Angular will not be able to tell which projected content has replaced which set of ng-content tags, we need to label the ng-content tags in some fashion to disambiguate them from one another. 

A simple way to label, or mark, the ng-content tags so that the intended projected content replaces the desired set of ng-content tags is to identify the elements by class names. We label the tags by using an attribute of ng-contentnamed select. Let's extend our contrived CarComponent example to see how this may look with two pairs of ng-content tags:

template: '<ng-content select=".question"></ng-content><ng-content select=".answer"></ng-content>'

Here is what the parent component would look like:

<car>
<h3 class="question">What production car has the fastest acceleration
time from 0 to 60?</h3>
<span select="answer"><strong>Tesla</strong></span>
</car>

By using ng-content tags, and its select attribute, if you have multiple content projection targets, you can create components that are customizable by developers that consume them. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.108.9