【发布时间】:2017-03-12 00:15:47
【问题描述】:
在角度 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>
-
<!-- sub1.html -->
<div>
<button>I'am sub1</button>
</div>
-
<!-- sub2.html -->
<div>
<div>I'am sub2</div>
</div>
【问题讨论】:
-
它没有任何角度上下文吗?或者只是
div和static text? -
确实如此。我有 {{}} 和 *ngIf, ngFor,... 但是如何在主模板中包含其他模板?
-
@natel 你的链接是关于 angular1-routing...不是我想要的
-
ng-include 不在 angular2 的范围内。你应该使用 CFR。