Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Angular 17 multiple content projection Error

I am learning Angular multiple content projection from new Angular 17 docs.
When I am using example from doc I am getting error:

profile.component.html::

<div class="red">
  <ng-content select="profile-header"></ng-content>
</div>

<div class="green">
  <ng-content></ng-content>
</div>

<div class="blue">
  <ng-content select="profile-footer"></ng-content>
</div>

In app.component.html::

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<app-profile>
    <profile-header><h2>Header 1</h2></profile-header>
    <p>This is projected content</p>
</app-profile>

I am getting this error::

NG8001: 'profile-header' is not a known element:

How can I resolve it?

>Solution :

The select is the equivalent of javascript query selector ( [<<attribute name>>] ) so you can do the attribute selector like so.

app.component.html

<app-profile>
    <h2 header>Header 1</h2>
    <p>This is projected content</p>
    <h2 footer>Footer 1</h2>
</app-profile>

profile.component.html:

<div class="red">
  <ng-content select="[header]"></ng-content>
</div>

<div class="green">
  <ng-content></ng-content>
</div>

<div class="blue">
  <ng-content select="[footer]"></ng-content>
</div>

docs here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading