angular 2包含html模板 [英] angular 2 include html templates
本文介绍了angular 2包含html模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,我想创建多个html模板,并将它们包含在主html文件中(例如ng1在angular1中包含)。
但是如何在子模板中包含子模板?
示例:
<! - test.html - >
< div>
这是我的子项目
<! - include sub1.html here - >
< / div>
< div>
这是第二个子项目
<! - 包含sub2.html这里 - >
< / div>
-
<! - sub1.html - >
< div>
< button> I'am sub1< / button>
< / div>
-
<! - sub2.html - >
< div>
< div> I'am sub2< / div>
< / div>
解决方案
您可以创建像sub1 sub2等组件。这些子组件将这些html文件添加为模板。
在主html上分别调用组件选择器。它将工作
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>
解决方案
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
这篇关于angular 2包含html模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文