需求:想用Angular实现Card组件,Card组件中要可以嵌入其他组件或者内容。

方法:使用ng-content

代码:

card.component.html

<div>
  card works!
  <div>
  <ng-content></ng-content>
  </div>
</div>

引入card组件的home.component.html

<app-card>
  <a>test</a>
</app-card>

相关文章:

  • 2022-12-23
  • 2021-07-09
  • 2021-05-13
  • 2022-12-23
  • 2018-01-09
  • 2021-04-13
  • 2021-11-19
猜你喜欢
  • 2021-07-12
  • 2021-12-02
  • 2021-07-18
  • 2021-09-25
  • 2022-12-23
  • 2021-12-28
  • 2019-10-21
相关资源
相似解决方案