I've created a simple datepicker directive which have an "options".
So I start the datepicker with a set of options, and then because of business logic I change those options, but this are not being refreshed.
In this example, I need to update de datepicker start date of the "endDate" to the same date as "startDate".
Here's my code:
Directive:
function datepicker() {
return {
restrict: "A",
scope: {
options : '='
},
link: function(scope, element, attrs) {
var opts = scope.options || {};
element.datepicker({
keyboardNavigation: false,
forceParse: false,
autoclose: true,
useCurrent: true,
format: opts.format || 'dd/mm/yyyy',
startDate : opts.startDate || ''
});
}
};
}
Controller:
$scope.evaluation = {};
$scope.startDatepickerOptions = {
startDate : new Date()
};
$scope.endDatepickerOptions = {
startDate : new Date()
};
$scope.$watch('evaluation.startDate', function(newValue) {
$scope.endDatepickerOptions.startDate = newValue;
});
View:
<input type="text" ng-model="evaluation.startDate" name="startDate" datepicker options="startDatepickerOptions"/>
<input type="text" ng-model="evaluation.endDate" name="endDate" datepicker options="endDatepickerOptions"/>