我在角度5中使用了矩v2.22.0,这就是我将其导入模块中的方式-
import * as moment from 'moment';
并将其在组件中用作-
export class ChatComponent {
.
.
.
public moment: any = moment;
.
.
}
当我在html模板中使用它时-
<div>{{moment(activeTeam.createdAt).format('LL')}}</div>
它给我一个错误消息-
[Angular] Member 'moment' is not callable
谁能告诉我我做错了!!
答案 0 :(得分:5)
cli(在控制台中运行)
// install moment js
npm install moment --save
组件声明(ts)
// import and declare moment
import * as moment from 'moment';
moment: any = moment;
模板文件(html)
// template syntax
<p>{{moment(date_time_variable).format('ll')}}</p>
答案 1 :(得分:0)
而不是将矩型声明为任何类型,而是将其声明为moment: () => any;
答案 2 :(得分:0)
尝试将moment
导入为:
import moment from 'moment';
HTML:
<div>{{getFormat(activeTeam)}}</div>
TS:
getFormat(activeTeam){
return moment(activeTeam.createdAt).format('LL')
}
答案 3 :(得分:0)
删除* as
表单导入
要从moment
来安装npm install moment --save
import moment from 'moment';
export class ChatComponent {
moment: any = moment;
}
<div>{{moment(activeTeam.createdAt).format('LL')}}</div>
答案 4 :(得分:0)
不要使用any
,在没有声明的情况下声明
import * as moment from 'moment';
moment = moment;