使用Angular 1.5.2,UI引导程序1.2.5,引导程序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-06-12"startM":"2014-06-12T04:00:0.000Z"
在控制台中,我可以显示启动M:o_d: 2014年6月12日星期四00:00:00 GMT-0400(东部夏令时)_f: "YYYY-MM-DD"_i: "2014-06-12"_isAMomentObject:true_isUTC:false_isValid:true_区域设置:
输入字段为空????
当我点击日历查看日期时,它选择了正确的日期,如果我选择它,它将正确显示在输入字段中。
<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];
我知道我没有提供太多细节,但我很难理解为什么日历知道正确的日期,但输入框没有。。。
您有minDate: new Date()
。那是今天,但您正试图将日期设置为2014年6月12日,这比您指定的最短日期要短。这可能就是为什么它是空白的。
问题是uib日期选择器弹出窗口似乎需要uibDateParser生成的日期。你需要这样做,而不是使用moment.js:
$scope.item.start = uibDateParser.parse($scope.item.start, "yyyy-MM-dd")
我不能告诉你为什么它在弹出窗口中正确显示,但在文本框中没有显示,但我确信它就是现在的样子。