typescript - 如何在 ngx-countdown 中将数据动态绑定到 leftTime
问题描述
我正在使用 ngx-countdown npm 包在我的网页上显示倒计时。我想根据来自后端的数据设置 leftTime 属性,我尝试了以下方式,但它不起作用,
在我的html中,
<countdown #cd [config]="notifyConfig" (event)="handleEvent($event)"></countdown>
在我的 component.ts
notifyConfig: CountdownConfig = { leftTime: this.consultationDurationInSeconds, notify: [120], format: 'mm:ss', };
this.consultationDurationInSeconds = data.ConsultationDuration.Minutes*60;
我的数据对象有我想绑定到 leftTime 属性的分钟。但是当我尝试这种方式时,它会显示错误消息,
** 无法将“无效日期”转换为日期 **,
谁能帮我解决这个问题?
解决方案
你可以这样做
首先声明一个包含你想要的时间的字符串,
let TimeString = "20:00";
startCountDown() {
if (this.timer > 0) {
this.TimeString = this.getFormattedTime();
this.timer--;
}
}
getFormattedTime() {
const duration = moment.duration(this.timer, 'seconds');
const resultstring = moment.utc(duration.asMilliseconds()).format('mm:ss');
return resultstring;
}
您只想调用 startCountDown() 函数。
推荐阅读
- node.js - 获取嵌入 PowerBi Angular 8 的正确令牌
- javascript - react hooks 为什么我的拖放项目卡住了?
- javascript - 在MVC中动态添加时如何在每行上将行号值设置为Textboxfor
- c++ - 自定义 CFileDialog 时如何控制新控件的大小和位置?
- javascript - 如何触发按钮点击按键
- javascript - 在 JavaScript 中添加一个简单的 counter[i] 变量以附加到 wrapper.append(container);
- python - 程序不将值识别为有效的变量值?
- java - 从中运行批处理文件后如何继续执行Java类
- r - strucchange 中的 breakdates 给出浮点数而不是日期
- git - GitHub Pages 显示白页