我在正确设置数据格式时遇到问题,以便 AngularJS 将数据填充为“时间”类型的输入字段。你能帮我弄清楚我缺少什么吗?
HTML:
<input type="time" id="exampleInput" name="input" ng-model="stuff.starttime"
placeholder="HH:mm:ss" min="00:00:00" max="17:00:00" >
Controller :
$scope.stuff = {
originlevel2: "",
destinationlevel2: "",
destination2: "",
origin2: "",
starttime: "",
endtime: ""
}
var starttime = jsonArray2[0]["starttime"];
$scope.stuff.starttime = new Date(starttime);
最佳答案
因为 jsonArray2[0]["starttime"]
的值为 01:00:00
。
因此,new Date(jsonArray2[0]["starttime"])
是无效日期。
您可以改为以下内容:
var d=new Date();
starttime='01:00:00' // jsonArray2[0]["starttime"]
starttime=starttime.split(':').map((e)=>parseInt(e))
d.setHours(starttime[0]);
d.setMinutes(starttime[1]);
d.setSeconds(starttime[2]);
// Then
$scope.stuff.starttime= d;
之后,尝试使用 Chrome 或 safari 。
<小时/>Note :
Note: type="time" is not supported in Firefox, or Internet Explorer 10 and earlier versions.
关于javascript - 输入[时间]不接受来自 Controller 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38666576/