I have to develop a reusable component similar to this one:
It has two container parts that can hold other components unknown at the time, the main content part and the menu part:
Googling around, I have found an example that uses the ng-content
directive, but I don't know if it can be used more than once or not (it's the first time I use Angular for a project). This is the idea:
<!-- WindowComponent -->
<div class="window">
<h4>Window title</h4>
<ng-content></ng-content>
</div>
<!-- Content -->
<div class="content">
<app-window>
<div>Some content</div>
</app-window>
<!-- How about the menu? -->
</div>
You can use
<ng-content>
with select. Like this:Usage:
Live demo
<ng-content select="...">
supports selecting by:<ng-content select=".my-css-class">
<ng-content select="[my-directive]">
<ng-content select="my-component">
Yes you can use more than once in a component. You can break your view in to few components if needed.
Container component
Menu component
Graphs/Content component
And you can put menu component and the graphs component in to container component's template.