I am trying to add a datepicker via an Angularjs Directive while passing the element as shown below and it's not working, but if I specify an element id, it works fine:
HTML:
<input id="startdate" type="text" ng-model="i.itinerary.DapartDate" date-from />
app.js:
Not Working:
travelApp.directive('dateFrom', function () {
return function (scope, element, attrs) {
element.datepicker({ minDate: currentTime });
element.change(function () {
currentTime = element.val();
});
}
})
WORKING
travelApp.directive('dateFrom', function () {
return function (scope, element, attrs) {
$("startdate").datepicker({ minDate: currentTime });
$("startdate").change(function () {
currentTime = $("#startdate").val();
});
}
})
Unfortunately I can not use controls ids, because I have an array of start and end dates in my itinerary list, so I need to bind this function to every newly created date element in itinerary array. Please advise.