I have a value called
changes.lastUpdatedTime.currentValue
which is set to 1540460704884
. I am looking to format this value using a pipe for date formatting.
For example, I want to achieve something like this:
{{lastUpdatedTime | date:'short'}}
How can I use the pipe inside the component?
${changes.lastUpdatedTime.currentValue} | date:'short'
I would like to implement something similar to this.
Here is the code snippet:
ngOnChanges(changes: SimpleChanges): void {
if (changes.typeLabel && changes.cardLabel && changes.severity) {
this.title = \`[${this.severityName}] ${changes.cardLabel.currentValue}
Type: ${changes.typeLabel.currentValue}
Status changed: ${changes.lastUpdatedTime.currentValue}\`;
}
}
I attempted to use the following code but it did not work as expected.
${changes.lastUpdatedTime.currentValue.transform(myDate, 'yyyy-MM-dd')}
Even though I tried the method shown above, it did not yield the desired result.
ngOnChanges(changes: SimpleChanges): void {
if (changes.typeLabel && changes.cardLabel && changes.severity) {
let displayedLastUpdatedTime = new DatePipe().transform(changes.lastUpdatedTime.currentValue);
this.title = `[${this.severityName}] ${changes.cardLabel.currentValue}
Type: ${changes.typeLabel.currentValue}
Status changed: ${displayedLastUpdatedTime}`;
}
}
However, executing the above code resulted in the error message
"has no exported member 'DatePipe'"
.
Thank you!