Ivan Ivan - 9 months ago 55
Javascript Question

Angular2.0.0 pipe '' could not be found


Error: Template parse errors: The pipe 'datefromiso' could not be


import {Pipe, PipeTransform} from "@angular/core";

name: 'datefromiso'
export class DateFromISO implements PipeTransform {
transform(value: any, args: string[]): string {
if (value) {
var date = value instanceof Date ? value : new Date(value);
return date.getDate() + '/' + (date.getMonth()+1) + '/' + (date.getYear()+1900);

App module:

import { DateFromISO } from './pipes/date-from-iso';
bootstrap: [ App ],
declarations: [


<div class="pull-right">{{entity.ts | datefromiso}}</div>

is ISO string. What's wrong?
Also a question: if there are better way to transform ISO string to locale date in html with angular2?
Thanks in advance.

Answer Source

You need to add the module that contains DateFromISO to imports of every module where you use it.

It's therefore advisable to create a feature module that contains the pipe and perhaps other reusable directives and components and then add this module to imports in all modules where they should be available.

The pipe and other reusable components and directives need to be added to declarations and exports in this feature module.