Angular2.0.0 pipe '' not found

Error:

Error: Template parsing errors: "datefromiso" in pipe cannot be found

Trumpet:

import {Pipe, PipeTransform} from "@angular/core"; @Pipe({ 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); } } } 

Application module:

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

HTML:

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

entity.ts is an ISO string. What's wrong? Also a question: if there is a better way to convert an ISO string to a localization date in html using angular2? Thanks in advance.

+5
source share
1 answer

You need to add a module containing DateFromISO to imports each module in which you use it.

Therefore, it is recommended to create a functional module that contains the channel and, possibly, other reusable directives and components, and then add this module to imports in all modules where they should be available.

In this function module, you must add components and directives to declarations and exports to reuse pipes and other components.

+6
source

Source: https://habr.com/ru/post/1259034/


All Articles