我想创建一个像模板一样的组件。例如,与其在各处编写:
<div class="myClass">
<div class="myHeader" id="headerId"> Title </div>
<div class="myContent" id="contentId"> <<Some HTML code>> </div>
</div>
我想使用像这样的组件:
<my-component title="Title" headerID=headerId contentID=contentID>
<<Some HTML code>>
</my-component>
我该如何在Angular2中实现类似的功能?
<ng-content></ng-content>
在您的组件中使用。
my.component.html
<div class="myClass">
<div class="myHeader" id="headerId"> Title </div>
<div class="myContent" id="contentId"> <ng-content></ng-content> </div>
</div>
parent.component.html
<my-component title="Title" headerID=headerId contentID=contentID>
<<Some HTML code>>
</my-component>
里面的东西<my-component></mycomponent>
都会被渲染成<ng-content></ng-content>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句