【问题标题】:Angular Nested, Arbitrary Content Projection角度嵌套,任意内容投影
【发布时间】:2020-07-04 04:41:37
【问题描述】:

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

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

【问题讨论】:

    标签: angular ng-content


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2019-04-19
      • 1970-01-01
      • 1970-01-01
      • 2022-10-19
      • 2018-01-06
      • 2021-06-19
      • 1970-01-01
      • 2015-05-12
      • 1970-01-01
      相关资源
      最近更新 更多