0

I have an Angular Component, the HTML looks something like this:

<!Doctype HTML>
<html>
<body>
<div class="main">
  <div [ngClass]="{'parent' : loading, 'parent-no-anim': !loading}">
   <div class="child">
   </div>
  </div>
</div>
</body>
</html>

And I implement that Component in another Component like this:

<app-mat-loading-card [loading]="device.loading || device.connecting">

Now I want to add other things in this Tag aswell, like a regular Span or something.

<app-mat-loading-card [loading]="device.loading || device.connecting">
<span class="button-title">{{device.deviceName}}</span>
</app-mat-loading-card>

I tried looking in Chrome Dev Tools, but I did not found anything in that Component Tag.

But whatever I try, nothing gets displayed. Whatever I put in that Component Tag, disappears. It would be kind if anyone could help me out, thanks :)

1 Answer 1

2

In angular, whatever you put between the component tags will disappear as default behaviour. You can however project what is between the component tags inside the component itself. This is normally handled with the <ng-content> tag.

What you put between the component tags will show up in place of the ng-content tags.

Official Docs on content projection: https://angular.io/guide/content-projection

An article I wrote about it, with examples: https://dev.to/renaisense_/angular-content-projection-and-solid-code-ng-content-5940

Hope this helps in guiding you to the right approach

Sign up to request clarification or add additional context in comments.

1 Comment

MAN I THANK YOU SO MUCH, I SPENT HOURS TRYING TO SOLVE THIS!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.