我试图在两个日期上运行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对象,该对象也以相同的日期/时间格式格式化。我想减去当前的本地时间(如组件formatted_date中定义的,与我从JSON数据返回的内容相比)。
我的HTML代码(基于该网站所说的内容):
<div *ngFor="let i of json">
<span>{{formatted_date | amDifference : i['Date'] : 'days'}}</span>
<div>要安装angular-moment模块,我已经运行了npm install angular-moment并使用:import * as moment from 'moment';导入了我的component.ts
发布于 2018-07-18 02:35:44
你正在尝试使用带有角的angularjs库。上面的库目前只支持angularjs版本。
这是一个过滤器,你想用的是管子。我建议你使用angular2-moment
试试import {MomentModule} from 'angular2-moment/moment.module';
之后
npm install angular2-momenthttps://stackoverflow.com/questions/51392729
复制相似问题