好的,我已经想通了。问题在于新的 Date([dateString]) 方法,它只接受某些值。我从第 1148 行开始编辑了 ui-bootstrap-tpls-0.6.0.js。如您所见,angular-ui 团队有一个 TODO ;-)
// TODO: reverse from dateFilter string to Date object
function parseDate(viewValue) {
if (!viewValue) {
ngModel.$setValidity('date', true);
return null;
} else if (angular.isDate(viewValue)) {
ngModel.$setValidity('date', true);
return viewValue;
} else if (angular.isString(viewValue)) {
var date = new Date(viewValue);
if (isNaN(date)) {
// If the date is inputted in the European dd.mm.yyyy format, it will be invalid
// This flips the month and the day around
var dLastPos = dateFormat.lastIndexOf('d');
var mPos = dateFormat.indexOf('M');
var dSep, newViewValue;
if(mPos>dLastPos){
dSep = dateFormat.substr(mPos-dLastPos,1);
newViewValue = viewValue.split(dSep);
if(typeof newViewValue=='object'){
newViewValue=newViewValue[1]+dSep+newViewValue[0]+dSep+newViewValue[2];
}
}
date = new Date(newViewValue);
if (isNaN(date)) {
ngModel.$setValidity('date', false);
return undefined;
} else {
ngModel.$setValidity('date', true);
return date;
}
} else {
ngModel.$setValidity('date', true);
return date;
}
} else {
ngModel.$setValidity('date', false);
return undefined;
}
}