Reputation: 753
I want to display the date in each column of my datatable. The date is comming via json and looks like:
JSON Date
1504836960000
Now i am formatting it via piping and ng-template:
<ng-template pTemplate="body" let-order="rowData">
{{order.sla.slaEnd | date:'yMdjm'}}
</ng-template>
I am getting a date looking like this: 8.9.2017, 04:16
Whole column code
<p-column field="sla.slaEnd" header="SLA">
<ng-template pTemplate="body" let-order="rowData">
{{order.sla.slaEnd | date:'yMdjm'}}
</ng-template>
</p-column>
The problem is, when sla.slaEnd == null
i am getting an error and my page collapses.
I have tried a lot but i didn't get it to check if sla.slaEnd != null
.
I want to check if it is null and when it is null he should display nothing like ''. When it is not null then just show my formatted date. Anybody knows how to solve this issue?
Upvotes: 1
Views: 1345
Reputation: 3453
Have you tried *ngIf=""
:
<p-column *ngIf="sla.slaEnd" field="sla.slaEnd" header="SLA">
<ng-template pTemplate="body" let-order="rowData">
{{order.sla.slaEnd | date:'yMdjm'}}
</ng-template>
</p-column>
Upvotes: 0