gpt4 book ai didi

html - angular 2 包括 html 模板

转载 作者:技术小花猫 更新时间:2023-10-29 12:01:57 26 4
gpt4 key购买 nike

在 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>

-

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

-

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

最佳答案

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

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

关于html - angular 2 包括 html 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40316341/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com