3

在Angular中,是否可以做类似的事情

<my-component>
  <h1>Some text</h1>
  <p>Some text</p>
  ...
</my-component

然后my-component让它变成

<div class="container">
  <h1>Some text</h1>
</div>
<div class="container>
  <p>Some text</p>
</div>
...

投影元素的数量和类型是任意的?每个子元素都需要放在一个 new<div class="container">中,但是子元素可以是任何类型,并且没有固定数量。

4

1 回答 1

0

这可以通过在主机组件中使用 ng-content 指令来实现。因此,在您的示例中, my-component 标记应如下所示 <ng-content><ng-content>

于 2020-12-24T07:05:18.097 回答