2015-09-14 44 views
0

我已經使用時間選擇接受預訂預訂後我已經存儲在database.in編輯預訂我已經通過了時間,時間輸入欄,但我得到的錯誤角度時間選擇器沒有得到錯誤?

Error: [ngModel:datefmt] Expected `01:00:00 pm` to be a date 
http://errors.angularjs.org/1.3.13/ngModel/datefmt?p0=01%3A00%3A00%20pm 
    at REGEX_STRING_REGEXP (angular.js:63) 
    at Array.<anonymous> (angular.js:19807) 
    at Object.ngModelWatch (angular.js:23289) 
    at Scope.promises.$get.Scope.$digest (angular.js:14235) 
    at Scope.promises.$get.Scope.$apply (angular.js:14506) 
    at done (angular.js:9659) 
    at completeRequest (angular.js:9849) 
    at XMLHttpRequest.requestLoaded (angular.js:9790).i have enclosed my code 

.controller('EditCtrl', [ 
 
     '$scope', '$http', '$location', '$window', '$filter', '$ionicPopup', '$ionicLoading', '$timeout', 
 
     function($scope, $http, $location, $window, $filter, $ionicPopup, $ionicLoading, $timeout) { 
 
    $http.get('**').success(function(data, dealers, response) { 
 
    // $scope.booktime = data.Scheduled_Time; 
 
    //console.log($scope.booktime); 
 
    $scope.booktime="01:00:00 pm"; 
 
}) 
 
    
 
} 
 
    ]);
<div ng-controller="EditCtrl"> 
 
    <div class="col"> 
 
      <label class="item item-input item-stacked-label"> 
 
      <span class="input-label" >Time</span> 
 
      <input type="time" ng-model="booktime" name="booktime" min="09:00:00" max="21:00:00"required=""> 
 
      </label> 
 
      <div class="form-error" ng-messages="projectForm.booktime.$error"> 
 
       <div class="form-error" ng-message="required">* Mandatory</div> 
 
       
 
       <div class="form-error" ng-message="max">Booking times: 9am - 9 pm</div> 
 
      </div> 
 
     </div> 
 
    </div>

+0

將其轉換爲日期對象,其不是日期 –

+0

該怎麼辦? –

回答

1

你必須以$scope.booktime = new Date(dateString)的形式使用。 NG-模型日期/時間輸入必須是有效的日期對象,所以你需要轉換成有效的日期對象

dt = new Date(); 
var time = dt.setHours(1) + ":" + dt.setMinutes(10) + ":" + dt.setSeconds(00); 
var date= dt.getFullYear() + "/" + dt.getMonth() + "/" +dt.getDay() + " "; 

$scope.booktime =new Date(date+ time;) 
+0

沒有它沒有選擇的值 –

+0

我已經把$ scope.booktime = new Date(data.Scheduled_Time);我在控制檯中獲取無效日期 –

+0

data.Scheduled_Time值是多少? –

0

你應該做類似下面的代碼,它會回報你正確的日期。

var date_yours= new Date(); 
    date_yours.setHours(1); 
    date_yours.setMinutes(10); 
console.log(date_yours); 

和格式化的日期(在你的情況下,你只需要時間)。我已評論上午/下午和使用24小時格式

function formatDate(date) { 
     var hours = date.getHours(); 
     var minutes = date.getMinutes(); 
    /* var ampm = hours >= 12 ? 'pm' : 'am'; 
     hours = hours % 12; 
     hours = hours ? hours : 12; // the hour '0' should be '12' */ 
     hours = hours < 10 ? '0'+hours : hours; 
     minutes = minutes < 10 ? '0'+minutes : minutes; 
     var strTime = hours + ':' + minutes; 
     //var strTime = hours + ':' + minutes + ' ' + ampm; 


     return strTime ; 

    } 
+0

* Mandatory
>

+0

我已經加了我的html –

+0

* Mandatory
>