我正在使用一个 angular-ui 日期选择器,一切都很正常,除了日期选择器的初始状态。在选择了一个日期后,它看起来很好。如下所示:
初始状态
选择日期后
显然,在第一种情况下,我得到的是日期对象的字符串化版本,在选择日期后则为格式化版本。
标记
<input type="text" class="form-control"
id="birthday"
datepicker-options="datePickerOptions"
datepicker-popup="{{format}}"
data-ng-model="birthday"
data-is-open="opened"
data-ng-required="true"
data-close-text="Close"/>
<span class="input-group-btn">
<button type="button"
class="btn btn-default"
data-ng-click="open($event)">
<i class="fa fa-calendar"></i>
</button>
</span>
控制器
var today = $scope.today = function today() {
$scope.birthday = $scope.client.birthday || new Date();
};
today();
$scope.clear = function clear() {
$scope.dt = null;
};
$scope.open = function($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.opened = true;
};
$scope.format = 'MMM d, yyyy';
$scope.datePickerOptions = {
'show-weeks': false
};
虽然不是很重要,但如果模型(根据文档需要是日期对象)最初就按照$scope.format
格式化而不是作为字符串化的日期对象格式化,那将会非常好。 另外,不确定是否有影响,但此日期选择器位于模态框内。 感谢您的任何帮助!
更新
看起来我不是唯一遇到这个问题的人,这与使用 Angular 1.3 相关。 https://github.com/angular-ui/bootstrap/issues/2659