2017-03-06 104 views
1

我有一个输入是这样的:输入[类型=时间]预计日期

<input type="time" ng-model="reunion.startHour" name="time" 
          placeholder="HH:mm:ss" min="08:00:00" max="20:00:00" class="form-control" 
          id="time" required /> 

,我从其中对象具有场time=08:00:00服务器获取数据。我想输入加载page.But时设置为该值我得到这个错误:

Error: [ngModel:datefmt] Expected 08:00:00 to be a date

现在,我已经试过这样:

$filter('date')(new Date(data.startHour), 'HH:mm'); 

但我得到invalid date

任何帮助将是appreciated.Thank你

+1

''? –

+0

新的日期(年,月,日,小时,分钟,秒,毫秒) – digit

+0

from angularDocs =>模型必须始终是一个Date对象,否则AngularJS会抛出一个错误。 – digit

回答

0

好了,遗憾的是JS不支持只是一个时间的日期。 HH:mm不是有效的日期格式:https://www.w3schools.com/js/js_date_formats.asp

您可以手动处理它,也可以使用虚假的日期作为您不关心的日期部分。

(我试图找到适合你的好时机对象的解决方案,但我没有看到太多在那里。希望别人具有更平滑的解决方案。)

0

作品在AngularJS 1.6

<input type="time" ng-model="startHour" name="time" 
    placeholder="HH:mm:ss" min="08:00:00" max="20:00:00" class="form-control" 
    id="time" required /> 

<br><p ng-show="startHour">{{startHour | date : 'shortTime' }}</p> 
<br><p ng-hide="startHour">Enter Valid Time</p> 
app.controller("myVm",function($scope) { 

    var vm = $scope; 

    vm.startHour = new Date(0); 
    vm.startHour.setHours(8); 

}); 

DEMO on PLNKR.

相关问题