javascript - 设置 Angular 模态的默认时间

标签 javascript angularjs time model default

如何在 Angular 模型中设置默认时间值?

HTML

<input id="starttime_mon" name="starttime_mon" ng-model="starttime[1]" ng-disabled="!search_dow_number[1]" type="time" class="form-control" />
<input id="endtime_mon" name="endtime_mon" ng-model="endtime[1]" ng-disabled="!search_dow_number[1]" type="time" class="form-control"  />

JS

$scope.starttime = new Date(1970, 0, 1, 0, 0, 0);
$scope.starttime = '00:00;
$scope.starttime[1] = new Date(1970, 0, 1, 0, 0, 0);

在最后一次尝试中,我得到:错误:无法设置未定义的属性“1” 我尝试过的其他方法没有给出任何结果。

最佳答案

所以new Date ,意味着$scope.starttime不是一个对象,因此它没有 1您尝试使用 $scope.starttime[1] 从中获取的属性

有点难以理解你的意思,但我认为你不需要 [1]:

JS

$scope.starttime = new Date(1970, 0, 1, 0, 0, 0);

HTML

<input id="starttime_mon" name="starttime_mon" ng-model="starttime" ...

关于javascript - 设置 Angular 模态的默认时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41590991/

相关文章:

是否使用 javascript 闭包(使用 angularjs 指令和 d3js 时)

javascript - 在javascript中将百分位转换为 “minutes:seconds.hundredths”

javascript - 使用 highstockJS 绘制纳秒图

javascript - 同时滚动 2 个不同的元素

javascript - Decimal.js tan 的精度问题

javascript - 新手 "first date formatting"脚本

java - 我如何比较java中没有格式和数据差异标题的csv

javascript - 在页面中包含 JavaScript 和 CSS (jQuery)

javascript - AngularJS 中的第一个、ng-include 或 ng-repeat 是什么?

javascript - Angular JS 中的必填字段验证