2013-11-25 31 views
0

我试图将date类型的input绑定到模型。我可以绑定到time字段,但我在date字段中遇到问题。该HTML:为什么我的AngularJS ngModel绑定到时间输入,但没有绑定到日期输入?

<div ng-app ng-controller="HistoryCtrl"> 
    <input type="date" nm-model="startDate" /> 
    <input type="time" ng-model="startTime" /> 
    <input type="date" nm-model="endDate" /> 
    <input type="time" ng-model="endTime" /> 
    <button ng-click="updateForm()">Update</button> 
</div> 

这是我的控制器(简体):

function HistoryCtrl($scope) { 

    $scope.result = { 
     result: 'success', 
     start: '2013-11-23 03:00:00', 
     end: '2013-11-24 16:30:00', 
     delta: 0.05681799352169 
    }; 

    $scope.updateForm = function() { 
     $scope.updateTimespan($scope.result.start, $scope.result.end); 
    }; 

    $scope.updateTimespan = function (start, end) { 
     $scope.startDate = start.split(" ")[0]; 
     $scope.startTime = start.split(" ")[1]; 
     $scope.endDate = end.split(" ")[0]; 
     $scope.endTime = end.split(" ")[1]; 
    } 
} 

这里有一个小提琴:http://jsfiddle.net/t3m6r/2/

我使用谷歌浏览器31.0.1650.57为Mac。当我点击“更新”按钮时,time字段更新,但date字段不更新。为什么?我是否doing it wrong

+2

也许是因为'纳米model'装置无关的角。 – Stewie

+3

这个问题似乎是脱离主题,因为它是关于错字。 – Stewie

回答

8

您正在使用ng-model,但输入错误“nm-model”。

<input type="date" ng-model="startDate" /> 
<input type="time" ng-model="startTime" /> 
<input type="date" ng-model="endDate" /> 
<input type="time" ng-model="endTime" /> 

参见JS Fiddle

+3

哇...哇。 –

相关问题