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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -