Error:
Error: Template parse errors: The pipe 'datefromiso' could not be found
Pipe:
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);
}
}
}
App 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 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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With