In a component I have a source code similar to this:
<ng-template let-col let-row="rowData" let-rowIndex="rowIndex" pTemplate="body">
<span *ngIf='row.job_id'>
{{row.job_id}}
</span>
<span *ngIf='!row.job_id'>
Job ID Not available
</span>
</ng-template>
I want to use else condition with it inside a single ng-template. how can I achieve it?
If you only need to change the text inside the span you can simple use :
{{ row.job_id ? row.job_id : 'Job ID Not available' }}
like this you avoid *ngIf
If you really want to use if/else this seem to work :
<ng-template let-col let-row="rowData" let-rowIndex="rowIndex" pTemplate="body">
<span *ngIf='row.job_id; else notAvailable'>
{{row.job_id}}
</span>
<ng-template #notAvailable>
<span>
Job ID Not available
</span>
<ng-template>
</ng-template>
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