1

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';

@Pipe({
    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';
...
@Page({
    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 :)

1 Answer 1

2

There is a missing comma after the template url

@Page({
    templateUrl: 'build/pages/page1/page1.html',  // << this comma here
    pipes: [DateToIso]
})
Sign up to request clarification or add additional context in comments.

2 Comments

After that i get the error Cannot find module '@angular2/core' from 'C:\Users\User\Desktop\tester\app\pipes' in the console so i changed the import from to 'ionic-angular' and now i get the error TypeError: (0 , _ionicAngular.Pipe) is not a function
@A.Ilazi It should be @angular/core, without 2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.