angular 2包括html模板

Tob*_*ler 20 html angular

在角度2我需要创建一个带有冗余部分的大型html模板.因此,我想创建多个html模板,并将它们包含在主html文件中(如angular1中的ng-include)

但是如何在主模板中包含子模板?

例:

<!-- test.html -->

<div>
    this is my Sub-Item
    <!-- include sub1.html here-->
</div>
<div>
    this is second Sub-Item
    <!-- include sub2.html here-->
</div>
Run Code Online (Sandbox Code Playgroud)

-

<!-- sub1.html -->
<div>
    <button>I'am sub1</button>
</div>
Run Code Online (Sandbox Code Playgroud)

-

<!-- sub2.html -->
<div>
    <div>I'am sub2</div>
</div>
Run Code Online (Sandbox Code Playgroud)

Asw*_* KV 15

您可以创建sub1 sub2等组件.在这些子组件上添加这些html文件作为模板.

在主html上分别调用组件选择器.它会工作