JavaScript Use AngularJS to add 30 days to current date and update days calculated when calendar value changes how to get current date in angularjs,angularjs add days

I have an AngulaarJS application where users select the day they want to view and it prints on the calendar the day and the next 30 days. The intended functionality needs to be so that when a user changes the day from the calendar it needs to show that day followed by the next 30 days.

As it stands my application shows todays date and the next 30 days but doesn't update the calendar when I change days on the date picker.

I am using the Angular Material datepicker:

<md-datepicker md-placeholder="Enter date" ng-model="myDate" ng-change="date_generator()" md-open-on-focus>
</md-datepicker>

This is the HTML I am using to print out the data:

<tr ng-repeat="date in futureDates">
    <td>
        {$ date | date : 'yyyy-MM-dd' $}
    </td>

And then my Angular function is:

$scope.date_generator = function() {
    $scope.currentDate = $scope.myDate;
    $scope.startDate = $scope.myDate; // Current moment
    $scope.endDate = new Date($scope.myDate.getTime() + 30*24*60*60*1000); // Current moment + 30 days
    $scope.iDate = new Date($scope.currentDate); // Date object to be used as iterator
    $scope.futureDates = new Array();
    $scope.futureDates.push( $scope.iDate.setDate($scope.iDate.getDate() - 0));
    while ($scope.iDate <= $scope.endDate) {
        $scope.futureDates.push( $scope.iDate.setDate($scope.iDate.getDate() + 1)); // Switch to next day
    }
}

Currently this is how the results look like

What am I doing wrong and what do I have to do to make the days on the calendar change whenever I change the date on the Date Picker?

Answer:1

I just tweaked your HTML a little and it worked for me:

  <tr ng-repeat="date in futureDates">
    <td>
      {{ date | date : 'yyyy-MM-dd' }}
    </td>
  </tr>

Here's a working JSFiddle, https://jsfiddle.net/rekrah/L67sy555/.

Answer:2

I would like to get a list of all the properties, styles, events and methods of an HTML element. Is there a reflection API in the browsers? I'm looking for something like this: var button = new ...

I would like to get a list of all the properties, styles, events and methods of an HTML element. Is there a reflection API in the browsers? I'm looking for something like this: var button = new ...

  1. does javascript run in browser or server
  2. does javascript run in browser

My function is like below. Consider for high performance, how can I avoid to add text in a loop structure in html? Please advise. Thank you so much. function createDiv (array) { var i; var ...

My function is like below. Consider for high performance, how can I avoid to add text in a loop structure in html? Please advise. Thank you so much. function createDiv (array) { var i; var ...

I have an assignment to create a battleship game, with 3x3 - 10x10 grid. My current idea would be to create a grid with a click of a button, or atlest change the current size with a click of a button. ...

I have an assignment to create a battleship game, with 3x3 - 10x10 grid. My current idea would be to create a grid with a click of a button, or atlest change the current size with a click of a button. ...

  1. create specific size file linux
  2. create specific size image
  3. create specific size file windows
  4. create specific size file
  5. create pdf specific size
  6. create a specific size rectangle in photoshop
  7. create list specific size python
  8. create partition specific size diskpart
  9. create dataframe specific size
  10. create file specific size powershell
  11. create vector specific size
  12. word create specific size
  13. create array of specific size python
  14. create array with specific size javascript
  15. create file of specific size mac
  16. create array of specific size matlab
  17. create array of specific size java
  18. create vector of specific size c++
  19. create arraylist of specific size
  20. create matrix with specific size matlab

I am creating a dynamic refresh feature for div elements on my site that need to be dynamically refreshed. $(document).ready(function() { function refreshDiv() { var refreshUrl =...

I am creating a dynamic refresh feature for div elements on my site that need to be dynamically refreshed. $(document).ready(function() { function refreshDiv() { var refreshUrl =...

  1. jquery bind elements