我想使用 moment.js 在我的 ionic 2 应用程序中显示谷歌地图中显示的标记的年龄。我已将 moment.js 安装为
npm install --save angular2-moment
angular2-moment 的文档解释了如何从模板中使用 amTimeAgo。但是我在类型脚本文件中找不到任何关于使用它的信息。所以我决定自己尝试一下。
首先,我在 app.module.ts 中导入了 TimeAgo 管道并提供了它
import { TimeAgoPipe } from "angular2-moment";
...........
providers: [
.............
TimeAgoPipe
]
但是,当我通过将此文件导入组件中创建此 TimeAgoPipe 的构造函数时,如下所示,我收到以下错误。
代码 :
import { TimeAgoPipe } from "angular2-moment";
...........
constructor(private timeAgoPipe: TimeAgoPipe) {}
错误 :
Uncaught (in promise): Error: No provider for ChangeDetectorRef