I am getting a date time value from asp.net mvc controller as \"2014-08-31T00:00:00Z\". When I bind this value to my angular-ui datepicker control it\'s state is showing as ng-i
This is best solution i found so far:
.directive('uibDatepickerPopup', function (dateFilter, uibDateParser, uibDatepickerPopupConfig) {
return {
restrict: 'A',
priority: 1,
require: 'ngModel',
link: function (scope, element, attr, ngModel) {
var dateFormat = attr.uibDatepickerPopup || uibDatepickerPopupConfig.datepickerPopup;
ngModel.$validators.date = function(modelValue, viewValue) {
var value = viewValue || modelValue;
if (!attr.ngRequired && !value) {
return true;
}
if (angular.isNumber(value)) {
value = new Date(value);
}
if (!value) {
return true;
} else if (angular.isDate(value) && !isNaN(value)) {
return true;
} else if (angular.isString(value)) {
var date = uibDateParser.parse(value, dateFormat);
return !isNaN(date);
} else {
return false;
}
};
}
};
});