我很好奇有没有办法在组件中重用两次ng-content?或者将其分配给组件构造函数中的变量?
就像是:
@Component({
selector: "component"
})
@View({
template: `<ng-content></ng-content> and again <ng-content></ng-content>`
})
我很好奇有没有办法在组件中重用两次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>