2

I am implementing my first angular library.

I want to achieve a header and footer library for angular. The problem is, that it should have the html of the app it is used in. Below you can find the sketch of the HTML code, I want to achieve.

//some header
<pageContent>
</pageContent>
//some footer

The pageContent.component should come from the app where the library is embedded. How do I achieve this?

EDIT:

I am trying to elaborate more:

In my angular library I have a component, which should have a header and a footer. Furthermore, it should show the main content of the page. Therefore, the library needs the input of the pageContent.component. How do I achieve this?

5
  • Can you elaborate more ? May be its just me, but I am unable to understand clearly Commented Jan 7, 2020 at 9:30
  • Done :-) I hope its clear now Commented Jan 7, 2020 at 9:38
  • Thanks Dieter. Take a look at the answer & demo code. Since you are new angular, I have put some routing in it to make it more closer to real life example. Commented Jan 8, 2020 at 3:59
  • Sorry for being late on my answer, since I had other work to do unfortunately. We are experimenting with Angular Libraries atm. But the tip with content projection did it :-) Commented Jan 16, 2020 at 11:31
  • Glad to hear that ! :) Commented Jan 17, 2020 at 6:12

1 Answer 1

3

Thank you for adding more details. Take a look at this demo code for reference

As you can see, I have used ng-content in canvas.component.html as below:

<div id='border'>
   <h3>header</h3>
    <ng-content>
      <!-- Dynamic content goes here -->
    </ng-content>
    <h3>footer</h3>
</div>

The canvas component contains the header and footer as you wanted. I have put some routing in this example to make it more close to what you are looking for.

I hope this has helped you. Cheers!

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.