Template parse: The pipe could not be found
Asked Answered
P

4

5

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?

Pythian answered 8/11, 2017 at 14:16 Comment(2)
Please create a reproduction of the problem to debug. The template-content you have shown seems irrelevant since the pipe mentioned in the error is amDateFormat not amTimeAgo.Retrusion
That was a copy/pasting error from when I was trying to debug and use other pipes from angular2-moment module. Example above is throwing the error when trying to use | amDateFormat:'LL' pipe also.Pythian
P
10

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

Pythian answered 9/11, 2017 at 0:50 Comment(0)
B
4

If this exists in the spec file (Jasmine, protractor)

import { MomentModule } from "ngx-moment";

beforeEach(() => {
    
      imports: [ MomentModule ]
  });

Worked for me

Bellyache answered 26/11, 2019 at 15:52 Comment(0)
M
3

In my case moving the MomentModule import from app.module.ts to the same module as component was fixed it.

Milton answered 4/7, 2019 at 21:11 Comment(0)
B
3

You can add momentModule to specific page module, or it'd be better to add it on shared module.

Hope it helps you.

Bushore answered 20/11, 2019 at 19:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.