首页 > 解决方案 > Angular6 创建可重用的 html 人工制品

问题描述

我对角度很陌生,所以请耐心等待。

我想创建一组 ui 元素。可以说,我有一个部分是这样的:

<section>
  <h2 class="section-title">Title</h2>
  <... html to make section collapsible .../>
  <div class="section-body">
    content goes here
  </div>
</section>

现在每次我想用这个,我必须复制粘贴它......

我是否有可能为此创建自己的模板?

<my-section title="Some Title" collapsible="true"> 
    content goes here 
</my-section>

标签: htmlangular

解决方案


请提供您的代码逻辑。

但我猜你正在寻找一些数据的迭代,而这里示例中的数据是items

<section>
  <h2 class="section-title">Title</h2>
  <... html to make section collapsible .../>
  <div class="section-body"  *ngFor="item of items">
    {{ item }}
  </div>
</section>

推荐阅读