gpt4 book ai didi

angular - 时刻在 Angular 5 html 模板中给了我错误

转载 作者:行者123 更新时间:2023-12-03 18:28:54 25 4
gpt4 key购买 nike

我在 Angular 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

谁能告诉我我做错了什么!

最佳答案

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>

关于angular - 时刻在 Angular 5 html 模板中给了我错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52037445/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com