how to add days to date variable on every ng-repeat loop in angularjs -


i have set date variable in "ng-init" directive , want add days date variable on every ng-repeat loop below:

<table>    <tr ng-repeat="n in myarr" ng-init="mydate=('07/25/2017'|date:adddays($index))">      <td ng-bind="mydate"></td>    </tr>  </table

you can instantiate first date in controler :

$scope.firstdate = new date('07/25/2017'); 

and add days in ngrepeat :

<tr ng-repeat="n in myarr" ng-init="mydate=(firstdate.setdate(firstdate.getdate() + 1)|date)"> 

and if want date format mm/dd/yyyy, need add @ end of nginit :'m/d/yyyy', (you can take @ the doc more information date format) :

<tr ng-repeat="n in myarr" ng-init="mydate=(firstdate.setdate(firstdate.getdate() + 1)|date:'m/d/yyyy')"> 

but if have other things dates think idea take @ moment.js

var app = angular.module('plunker', []);    app.controller('mainctrl', function($scope) {    $scope.firstdate = new date('07/25/2017');    $scope.myarr = [1, 2, 3, 4, 5];  });
<script data-require="angular.js@1.5.x" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js" data-semver="1.5.11"></script>    <table ng-app="plunker" ng-controller="mainctrl">    <tr ng-repeat="n in myarr" ng-init="mydate=(firstdate.setdate(firstdate.getdate() + 1)|date)">      <td ng-bind="mydate"></td>    </tr>  </table>


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -