将 MINUTES 放入 Progress 元素的 Max 属性中

Putting MINUTES in the Max Attribute on a Progress Element

所以我有一个 songDuration 变量:

例如:

this.songDuration = 4:20

我用的是angular4,所以我用的是插值法输入值

<progress value="{{songTime}}" max="{{songDuration}}"></progress>

执行此操作时,我在控制台中收到错误消息 "The provided double value is non-finite"。

如何将此变量转换为与 max 属性兼容的值?

试试这个

convert(input) {
    var parts = input.split(':'),
    minutes = +parts[0],
    seconds = +parts[1];
    return (minutes * 60 + seconds).toFixed(3);
}

然后

this.songDuration = this.convert('4:20');
this.songTime = this.convert('<something else>');

(有问题请留言)