Esta diretiva ajuda a usar o datepicker jQuery com angualrJs. Além disso (opcionalmente), preciso comparar com alguma data. (se a data não for fornecida em comparação com a data de hoje.
app.directive('ngDate', function() {
return {
restrict: 'A',
require : 'ngModel',
link : function (scope, element, attrs, ctrl) {
element.datepicker({
changeYear:true,
changeMonth:true,
dateFormat:'dd/M/yy',
onSelect:function (date) {
ctrl.$setViewValue(date);
if (attrs.hasOwnAttribute('futureDate'))
{
var dateToCompare=scope.$eval(attrs.futureDate);
if (!dateToCompare) dateToCompare=new Date();
(date>dateToCompare)?ctrl.$setValidity('future',true):ctrl.$setValidity('future',false);
}
scope.$apply();
}
});
}
};
});
<input type='text' data-ng-model='some.DateField' data-ng-date='' data-futurDate='some.DateToCompare' name='dateControl' readonly='readonly'>
<div class='error' data-ng-show='testForm.dateControl.$error.future'>
Date cannot be greater than some date.
</div>