我在使用angular-ui bootstrap日历时遇到了一个非常奇怪的问题。
以下是我创建的示例
http://plnkr.co/edit/V5UgCbfilCXX8nsube12?p=preview
场景是当页面着陆时它在ng-model变量中显示正确的日期但是当我从日历中选择日期时ng-model在UST中显示日期。
e.g。当我从日历中选择日期为“01/05/2012”时,ng-model binded属性显示为“2012-01-04T18:30:00.000Z”。我想要文本框中的内容,即“01/05/2012”。
如何克服这个问题。
<!doctype html>
<html ng-app="ui.bootstrap.demo">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.12.1.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
</head>
<script>
angular.module('ui.bootstrap.demo', ['ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('DatepickerDemoCtrl', function ($scope) {
$scope.today = function() {
$scope.dt = new Date();
};
$scope.dates = [{ date:'01/01/2012',isOpen:false, isDisabled:false}, {date:'05/05/2000',isOpen:false, isDisabled:false}, {date:'',isOpen:false, isDisabled:true}];
$scope.today();
$scope.clear = function () {
$scope.dt = null;
};
// Disable weekend selection
$scope.disabled = function(date, mode) {
return ( mode === 'day' && ( date.getDay() === 0 || date.getDay() === 6 ) );
};
$scope.toggleMin = function() {
$scope.minDate = $scope.minDate ? null : new Date();
};
$scope.toggleMin();
$scope.open = function($event, date) {
$event.preventDefault();
$event.stopPropagation();
date.isOpen=true;
$scope.opened = true;
};
$scope.dateOptions = {
formatYear: 'MM/dd/yyyy',
startingDay: 1
};
$scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
$scope.format = 'MM/dd/yyyy';
});
</script>
</head>
<body>
<div ng-controller="DatepickerDemoCtrl">
<h4>Popup</h4>
<br/>
<br/>
My Dates object {{dates}}
<br/>
<br/>
<div class="row" ng-repeat='x in dates'>
<span style="margin-left:20px">{{x.date}}</span>
<div class="col-md-6">
<p class="input-group">
<input type="text" class="form-control" datepicker-popup="{{format}}" ng-model="x.date" is-open="x.isOpen" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true" close-text="Close" />
<span class="input-group-btn">
<button type="button" ng-disabled="x.isDisabled" class="btn btn-default" ng-click="open($event,x)"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</p>
</div>
<br/>
<br/>
</div>
<hr />
</div>
</body>
</html>
答案 0 :(得分:0)
您的模型实际上具有正确的价值。 .000Z是秒的分数,Z表示UTC时区。
答案 1 :(得分:0)
这里有同样的问题:
Angular bootstrap datepicker date format does not format ng-model value
有人回答了这个问题。您可以参考上面的链接。
对我有用!