2013-11-25 36 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

哇...哇。 –

相關問題