我很好奇有什么方法可以在组件中重用两次ng内容吗?还是将其分配给组件构造函数中的变量?
类似于:
@Component({
selector: "component"
})
@View({
template: `<ng-content></ng-content> and again <ng-content></ng-content>`
})
发布于 2015-12-25 12:55:48
是的,我还找到了这个。
<my-component> <div content-a> A </div> </my-component>在构成部分:
<ng-content select="[content-a]"></ng-content>发布于 2017-08-22 06:57:00
在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>https://stackoverflow.com/questions/34461489
复制相似问题