[英]Is it possible to reuse <ng-content></ng-content> in component template? Angular2
我很好奇有没有办法在组件中重复使用两次ng-content ? 或者将它分配给组件构造函数中的变量?
就像是:
@Component({ selector: "component" }) @View({ template: `<ng-content></ng-content> and again <ng-content></ng-content>` })
在ng-template
的帮助下还有另一种方法
将ng-content
在ng-template
并将ngTemplateOutlet
与ng-container
例:
<ng-container *ngIf="YourCondition" *ngTemplateOutlet="content"></ng-container>
<ng-container *ngIf="!YourCondition" *ngTemplateOutlet="content"></ng-container>
<ng-template #content><ng-content></ng-content></ng-template>
用这个,
<my-component>Anything</my-component>
是的,我也发现了这个。
<my-component> <div content-a> A </div> </my-component>
在组件中:
<ng-content select="[content-a]"></ng-content>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.