文本字段停止使用AngularJs模型

时间:2015-11-13 23:16:52

标签: html angularjs

添加ng-model时,此文本字段停止工作:

<input type="time" value="23:20:50.52" />

为什么会发生这种情况,如何在具有预设值的时间字段中设置ng模型?

2 个答案:

答案 0 :(得分:0)

参考:https://docs.angularjs.org/api/ng/input/input%5Btime%5D

  
    

必须以有效的ISO-8601本地时间格式(HH:mm:ss)输入文本,例如:14:57:00。

         

模型必须是Date对象

  

前:

<script>
 angular.module('timeExample', [])
   .controller('DateController', ['$scope', function($scope) {
     $scope.example = {
       value: new Date(1970, 0, 1, 14, 57, 0)
     };
   }]);
</script>
<form name="myForm" ng-controller="DateController as dateCtrl">
 <input type="time" id="exampleInput" name="input" ng-model="example.value" />
</form>

答案 1 :(得分:0)

需要为标签分配ng-model的目的是什么?这样你就可以在控制器中指定一个值?如果是这种情况,您应该将值设置为角度范围变量并在控制器中定义值。标签是:

<input type="time" value="{{currentTime}}" />

在控制器中你会得到:

$scope.currentTime = "23:20:50.52";