The problem I am facing is that I have created a datepicker and I want to set its min date and max date based on the days I gather from a json.
The problem is that by the time the datepicker is initialised the $scope variables are null.
$scope.dates = [];
$scope.stats = {};
$scope.latestDay;
$scope.startDay;
$controller('rightsController', {
$scope : $scope
});
init();
$("#datepick").datepicker({
changeMonth: true,
changeYear: true,
buttonImageOnly: true,
dateFormat: 'dd/mm/yy',
minDate: ''+$scope.startDay,
maxDate: ''+$scope.latestDay
});
function init() {
fetchHourlyStats0();
}
$scope.fetchComparativeStats = function() {
fetchHourlyStats0();
}
function fetchHourlyStats0() {
var promiseStats = statsFactory.getHourlyStats();
$q.all([ promiseStats ]).then(function(values) {
$scope.stats = values[0].data;
i = 0;
for ( var k in $scope.stats) {
$scope.dates[i] = k;
var v = $scope.stats[k];
i++;
}
var length = $scope.dates.length-1;
$scope.latestDay = $scope.dates[0];
$scope.startDay = $scope.dates[length];
})
}
Is it possible to create the datepicker after the data access object is created and after I fill the variables?