我正在使用datePicker指令,该指令是JQuery datepicker的包装。 我仅在Firefox中通过格式设置日期时遇到格式问题(一年前的'-')。
在上图中,如果我单击选择器视图值,将被清除
正如我在Chrome中测试过的那样,IE10正常运行。
我打印的模型值低于视图值。我试图通过控制台访问范围值,即“ 2020年8月20日”。下面分别是我的指令和代码。
app.directive("datePicker", function () {
return {
restrict: "A",
require: "ngModel",
link: function (scope, elm, attr, ctrl) {
// Format date on load
ctrl.$formatters.unshift(function (value) {
if (value && moment(value).isValid()) {
var dtformat = "DD-MMM-YYYY" ;
return moment(new Date(value)).format(dtformat);
}
return value;
});
//Disable Calendar
scope.$watch(attr.ngDisabled, function (newVal) {
if (newVal === true)
$(elm).datepicker("disable");
else
$(elm).datepicker("enable");
});
var eledtformat = "dd-M-yy";
// Datepicker Settings
elm.datepicker({
autoSize: true,
changeYear: true,
changeMonth: true,
dateFormat: attr["dateformat"] || eledtformat,
showOn: "button",
buttonText: '<i class="pi pi-calendar"></i>',
onSelect: function (valu) {
scope.$apply(function () {
ctrl.$setViewValue(valu);
});
// elm.focus();
},
beforeShow: function () {
//
if (attr["minDate"] != null)
$(elm).datepicker("option", "minDate", attr["minDate"]);
if (attr["maxDate"] != null)
$(elm).datepicker("option", "maxDate", attr["maxDate"]);
}
});
}
};
});
<input ng-change="onChange()" ng-class="model[options.key] ? 'form-control' +' ui-state-filled' : 'form-control'"
type="text" date-picker placeholder='' ng-readonly="true" class='form-control'
ng-click="triggerDate($event)"
ng-model="model[options.key]" max-date="{{model[options.templateOptions.maxDate]}}" min-date="{{model[options.templateOptions.minDate]}}">
{{model[options.key]}}
请帮助我...