Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Template parse: The pipe could not be found

I am getting the error:

Template parse errors: The pipe 'amDateFormat' could not be found

Here is my app.module.ts

import { NgModule } from '@angular/core';
...
import { MomentModule } from 'angular2-moment';
...

@NgModule({
  declarations: [
    MyApp
  ],
  imports: [
    ...
    MomentModule,
    ...
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp
  ],
  providers: [
    ...
  ]
})
export class AppModule { }

Then in service-booking-details.ts I am doing the following:

import { Component} from '@angular/core';
import { IonicPage, NavController, NavParams} from 'ionic-angular';
import { MomentModule } from 'angular2-moment';
...    

@IonicPage()
@Component({
  selector: 'page-item-detail',
  templateUrl: 'service-booking-detail.html'
})
export class ServiceBookingDetailPage {
  service: any;
  ...

  constructor(..., navParams: NavParams, ...) {
    this.service = navParams.get('service');
  }
}

Then in the service-booking-detail.html template I am trying to use a pipe from angular2-moment:

<ion-content>

    <ion-card>
      <ion-card-content>
         <p>{{ service.data | amDateFormat:'LL' }}</p>
      </ion-card-content>
    </ion-card>

</ion-content>

It then throws the error "Template parse errors: The pipe 'amDateFormat' could not be found".

How do I import the MomentModule so that I can use it in templates without getting errors?

like image 549
coler-j Avatar asked Nov 08 '17 14:11

coler-j


People also ask

What is pipe in angular example?

Pipes were earlier called filters in Angular1 and called pipes in Angular 2 and 4. It takes integers, strings, arrays, and date as input separated with | to be converted in the format as required and display the same in the browser.


1 Answers

I was able to get this working by importing this into the specific pages *.module.ts file.

like image 55
coler-j Avatar answered Oct 18 '22 13:10

coler-j