Angular2 ng template

I am using 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>

Obviously, this will not work, and the solution will be to create the component. I saw in angular4 that something was causing ng-template. Is there anything similar in angular 2.4.X?

+4
source share
1 answer

There is a directive ngTemplateOutletthat can help you:

<template #myTemplate>
   foo
</template>
<header>
  <ng-container *ngTemplateOutlet="myTemplate"></ng-container>
</header>
<div>
  <ng-container *ngTemplateOutlet="myTemplate"></ng-container>
</div>
+8
source

Source: https://habr.com/ru/post/1672466/


All Articles