使用Angular 1.5.2,UI-Bootstrap 1.2.5,Bootstrap css 3.3.6
所以我的json数据以日期字符串形式出现(我无法帮助或改变它)。
"start": "2014-06-12"
我用时间转换为日期。 //从ajax调用返回的较大对象的一部分
$scope.item=data[0];
$scope.item.startM=moment($scope.item.start);
$scope.item.endM=moment($scope.item.end);
在{{item}}中,我在屏幕上直观地看到了 "开始":" 2014年6月12日" " startM":" 2014-06-12T04:00:00.000Z"
在控制台中我可以显示 startM:○ _d:2014年6月12日星期四00:00:00 GMT-0400(东部夏令时间) _f:" YYYY-MM-DD" _i:" 2014年6月12日" _isAMomentObject:真 _isUTC:假 _isValid:真 _locale:A
输入字段为空白????
当我点击日历以查看日期时,它选择了正确的日期,如果我选择它,将在输入字段中正确显示。
<input type="text" class="form-control" uib-datepicker-popup="{{format}}" ng-model="item.end" is-open="popup2.opened" datepicker-options="dateOptions" ng-required="true" close-text="Close" alt-input-formats="altInputFormats" /><span class="input-group-btn"><button type="button" class="btn btn-default" ng-click="open2()"><i class="glyphicon glyphicon-calendar"></i></button> </span>
$scope.dateOptions = {
formatYear: 'yy',
maxDate: new Date(2020, 5, 22),
minDate: new Date(),
startingDay: 1
};
$scope.formats = ['yyyy-MM-dd','dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
$ scope.format = $ scope.formats [0];
我知道我没有提供太多细节,但我很难理解为什么日历知道正确的日期,但输入框没有......
答案 0 :(得分:1)
你有minDate: new Date()
。那是今天,但是您试图将日期设置为2014年6月12日,该日期小于您指定的最短日期。这可能就是为什么它是空白的。
答案 1 :(得分:0)
问题是 uib-datepicker-popup 似乎需要由 uibDateParser 生成的日期。你需要做这样的事情而不是使用moment.js:
$scope.item.start = uibDateParser.parse($scope.item.start, "yyyy-MM-dd")
我无法告诉您为什么它在弹出窗口中正确显示,而在文本框中却没有显示,但我确信此时它就是这样。