1

I've the following array with numbers that are representing days of week:

  • 0 is for sunday
  • 6 is for saturday

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?

1 Answer 1

1

**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

      }

    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.