我收到错误消息:
模板解析错误:找不到管道“amDateFormat”
这是我的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 { }
然后在service-booking-details.ts
我做以下事情:
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');
}
}
然后在service-booking-detail.html
模板中,我尝试使用来自 angular2-moment 的管道:
<ion-content>
<ion-card>
<ion-card-content>
<p>{{ service.data | amDateFormat:'LL' }}</p>
</ion-card-content>
</ion-card>
</ion-content>
然后它抛出错误“模板解析错误:找不到管道'amDateFormat' ”。
如何导入 MomentModule 以便在模板中使用它而不会出错?