Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular 2 include html templates

Tags:

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>
like image 425
Tobias Koller Avatar asked Oct 29 '16 05:10

Tobias Koller


People also ask

Can I use HTML template in Angular?

An Angular HTML template renders a view, or user interface, in the browser, just like regular HTML, but with a lot more functionality. When you generate an Angular application with the Angular CLI, the app. component. html file is the default template containing placeholder HTML.

What is a template in angular 2?

Angular 2 templating system gives us a syntax to express the dynamic part of our HTML. In Angular 2, a component needs to have a view. To define a view, you can define a template inline (using template) or in a separate file (using templateUrl).


1 Answers

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

like image 195
Aswin KV Avatar answered Oct 05 '22 17:10

Aswin KV