2015-09-14 25 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
>