Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 ng-template

Tags:

html

angular

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 ?

like image 673
Scipion Avatar asked Dec 18 '22 08:12

Scipion


1 Answers

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>
like image 130
yurzui Avatar answered Dec 30 '22 09:12

yurzui