Reputation: 847
I've the following array with numbers that are representing days of week:
var available = [1, 2, 3... whatever];
It loads the days dynamically from for cycle:
for (var i = 0; i < data.length; i++) {
var pos = data[i].position;
available.push(pos);
}
I assign a function called "severalDays" that filters the days available:
$scope.severalDays = function(date) {
// I want access to available array here
}
In my HTML I've the md-datepicker line:
<md-datepicker ng-model="availableCalendar" md-date-filter="severalDays"></md-datepicker>
How I could do it?
Upvotes: 1
Views: 629
Reputation: 847
**SOLVED**
$scope.severalDays = function (date) {
var day = date.getDay(); //I got generic day from 0 to 6 (0 for sunday, 6 for saturday);
for(var i = 0; i < available.length; i++){
var len = available.length; //length of available array
var currentPos = available[i]; //current position of array
var nextPos = available[(i+1)%len]; //next position of array
var previousPos = available[(i+len-1)%len]; //previous position of array
return day === currentPos || day === nextPos || day === previousPos; //THE RETURN
}
}
Upvotes: 1