I am curious is there any way to reuse twice ng-content in component? Or to assign it to variable inside component constructor?
Something like:
@Component({
selector: "component"
})
@View({
template: `<ng-content></ng-content> and again <ng-content></ng-content>`
})
There is also an other way of doing it with the help of ng-template
Wrap the ng-content
inside ng-template
and use ngTemplateOutlet
with ng-container
Example:
<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>
Use this as,
<my-component>Anything</my-component>
Yes, i also found this.
<my-component> <div content-a> A </div> </my-component>
and in component:
<ng-content select="[content-a]"></ng-content>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With