A. Ilazi A. Ilazi - 5 months ago 262
MySQL Question

How to format MySQL datetime to angular2 useable date format in Ionic 2?

I am trying to format a mysql datetime that looks like this: 2016-05-27 20:17:45 to an useable date format for angular2. After reading some comments how this could be done I created a custom pipe:

import {Pipe} from 'angular2/core';

name: 'dateToIso'
export class DateToIso {
transform(value, args) {
let newValue = new Date(value).toISOString();
return newValue;

Then I imported the pipe to the page where to use it and defined it in the decorator to use it in the HTML file.

import {DateToIso} from '../../pipes/date-ToIso';
templateUrl: 'build/pages/page1/page1.html'
pipes: [DateToIso]

When using the new created pipe in the HTML file:
{{ post[2] | dateToIso}}
I get the error:

Error: Uncaught (in promise): Template parse errors: The pipe
'dateToIso' could not be found

What am I doing wrong? Thanks to all :)


There is a missing comma after the template url

    templateUrl: 'build/pages/page1/page1.html',  // << this comma here
    pipes: [DateToIso]