我发现了一个错误:
模板解析错误:找不到管道'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时刻使用管道()。
<ion-content>
<ion-card>
<ion-card-content>
<p>{{ service.data | amDateFormat:'LL' }}</p>
</ion-card-content>
</ion-card>
</ion-content>然后抛出错误“模板解析错误:找不到管道'amDateFormat‘”。
如何导入MomentModule,以便在模板中使用它而不会出现错误?
发布于 2017-11-09 00:50:57
通过将它导入到特定的页面*.module.ts文件中,我就能够做到这一点。
发布于 2019-11-26 15:52:21
如果在规范文件中存在这种情况(茉莉花,量角器)
import { MomentModule } from "ngx-moment";
beforeEach(() => {
imports: [ MomentModule ]
});为我工作
发布于 2019-07-04 21:11:07
在我的例子中,将MomentModule导入从app.module.ts移到与组件相同的模块中是固定的。
https://stackoverflow.com/questions/47182015
复制相似问题