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?
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/.
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 ...
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. ...
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 =...