如何在 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/