Tobias Koller Tobias Koller - 1 month ago 16
HTML Question

angular 2 include html templates

in angular 2 I need to create a large html-template with redundant parts.
Therefore I want to create multiple html-templates and put them together by including them in the main html-file (like ng-include in angular1)

But how can I include sub-templates in the main-template?

example:

<!-- test.html -->

<div>
this is my Sub-Item
<!-- include sub1.html here-->
</div>
<div>
this is second Sub-Item
<!-- include sub2.html here-->
</div>


-

<!-- sub1.html -->
<div>
<button>I'am sub1</button>
</div>


-

<!-- sub2.html -->
<div>
<div>I'am sub2</div>
</div>

Answer

You can create components like sub1 sub2 etc. And On those child components add these html files as template .

On main html call the component selectors respectively. It will work