0

I want my static menu to be inside my both children components, how to achieve that?

I tried with ng-template, ng-content, ng-container, ngTemplateOutlet directives but I didn't find an example that works with router-outlet. enter image description here

I don't want to duplicate my menu in children.

Here is start with stackblitz

A. Morel
  • 9,210
  • 4
  • 56
  • 45

1 Answers1

1

You can create a common component to be reused:

export class MenuComponent implements OnInit {}

Place the menu related css and html in the component's css and html file.

Once you done that, you can place it in your child component's html like:

Child 1

<div>
    <app-menu></app-menu>
    <p>Child 1</p>
</div>

Child 2

<div>
    <app-menu></app-menu>
    <p>Child 2</p>
</div>
Jai
  • 74,255
  • 12
  • 74
  • 103
  • Ok it was not what I was looking for, but I think there is no other way... That's what I finally doing too. – A. Morel Dec 22 '22 at 08:29