gpt4 book ai didi

javascript - Angular 时间选择器没有收到错误?

转载 作者:行者123 更新时间:2023-12-03 08:54:18 25 4
gpt4 key购买 nike

我在预订后使用时间选择器进行预订,我已将其存储在数据库中。在编辑预订时,我不时通过输入字段,但收到错误

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>

最佳答案

您必须以$scope.booktime = new Date(dateString)的形式使用。用于日期/时间输入的ng-model需要是有效的日期对象,因此需要转换为有效的日期对象

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;)

关于javascript - Angular 时间选择器没有收到错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32570395/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com