Saturday 18 June 2022

ng-container with ngTemplateOutlet and ng-template with context variable

<div *ngIf="!multiOptionsChart.length" class="row">
<ng-container *ngTemplateOutlet="
chartBlock;
context: {
optionItem : options,
chartType:'single'
}">
</ng-container>
</div>

<div *ngIf="multiOptionsChart.length" class="row">
<div *ngFor="let optionItem of multiOptionsChart; let i = index">
<ng-container *ngTemplateOutlet="
chartBlock;
context: {
optionItem : optionItem ,
chartType:'multi'
}">
</ng-container>
</div>
</div>

<ng-template #chartBlock
let-optionItem="optionItem"
let-chartType="chartType">

<div class="graph-action">
your multi and single chart type common code
</div>

<ng-container *ngIf="chartType === 'multi'">
<span>chartType</span>
<span>: {{ chartType }}</span>
</ng-container>
<ng-container *ngIf="chartType === 'single'">
<span>single chartType</span>
<span>: {{ chartType }}</span>
</ng-container>
Name : {{ optionItem.name }}
</ng-template>


No comments:

Post a Comment