这是我的 HTML:
<input [(ngModel)]="ask.start" type="number" min="0"/>
我需要使用type="number"
,因为用户会有这样的问题
"In how many days do you want to see this"
然后是输入
。
[(ngModel)]
值是天数。我需要以某种方式将其转换为毫秒,这样我就可以获得毫秒值并存储它。
编辑:1 天(以毫秒为单位)的公式为 24 * 60 * 60 * 1000
我该怎么做?这几天我一直在为这件事发疯。
谢谢。
最佳答案
您应该创建一个自定义管道。
@Pipe({ name: 'myPipe'})
export class MyPipe implements PipeTransform{
transform(val) {
return val * 24 * 60 * 60 * 1000
}
}
像这样更改您的输入:
<input [(ngModel)]="ask.start | myPipe" type="number" min="0"/>
相关问题:Using Pipes within ngModel on INPUT Elements in Angular2-View
关于javascript - 如何在 ngModel 中转换为毫秒?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43062591/