I am using the version 2.4.9 of Angular. I would like to declare an html element that I can use in several places :
<div #template>
foo
</div>
<header>
{{ template }}
</header>
<body>
{{ template }}
</body>
It obviously doesn't work, and the solution would be to create a component. I have seen in angular4 that something calls ng-template
does exist. Is there anything similar in angular 2.4.X ?
There is ngTemplateOutlet
directive that can help you:
<template #myTemplate>
foo
</template>
<header>
<ng-container *ngTemplateOutlet="myTemplate"></ng-container>
</header>
<div>
<ng-container *ngTemplateOutlet="myTemplate"></ng-container>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With