找不到角矩管道“ amDifference”

时间:2018-07-18 02:31:05

标签: angular typescript angular-moment

我正在尝试从以下两个日期运行amDifference计算: https://github.com/urish/angular-moment#amdifference-filter

我得到的错误:

Uncaught Error: Template parse errors:
The pipe 'amDifference' could not be found ("yling">{{i['Date']}}</td>-->
                                    <td class="date-font-styling">{{[ERROR ->]formatted_date | amDifference : i['Date'] : 'days'}}</td>
                                    </tr"): ng:///LayoutModule/AboutComponent.html@213:68
    at syntaxError (compiler.js:485)
    at TemplateParser.parse (compiler.js:24668)
    at JitCompiler._parseTemplate (compiler.js:346

我要做什么:

在我的component.ts中,我为日期和时间格式为YYYY-MM-DD HH-MM-SS的本地当前时间定义了一个变量。在HTML的正面,我有一个按钮,它调用component.ts中的一个函数,该函数从我的API中返回一个包含日期的JSON对象,该日期也采用相同的日期/时间格式。我想减去当前本地时间(相对于我从JSON数据返回的时间而言,如在formatted_date组件中定义)。

我在HTML中的代码(基于该网站所说的内容)

<div *ngFor="let i of json">
<span>{{formatted_date | amDifference : i['Date'] : 'days'}}</span>
<div>

要安装angular-moment模块,我已经运行npm install angular-moment并使用以下命令导入到我的component.ts中:import * as moment from 'moment';

1 个答案:

答案 0 :(得分:0)

您正在尝试将angularjs库与angular一起使用。上面的库目前仅支持angularjs版本。

这是您要使用s管道的过滤器。我建议您使用 angular2-moment

尝试import {MomentModule} from 'angular2-moment/moment.module';

之后

npm install angular2-moment