Reputation: 99
Here is my current MomentJS
code:
var date = moment($scope.dt);
for (var i = 0; i < parseInt($scope.numPagos); i++) {
$scope.resultados.push({
'numerodecuota' : i + 1,
'fechas' : date.add(1, 'days').format("MM/DD/YYYY"),
'pagos' : Math.round($scope.importeprestamo / $scope.numPagos + interes),
'interes' : Math.round(interes),
'capital' : $scope.importeprestamo / $scope.numPagos,
'fechaunix' : date.add(1, 'days').unix()
});
}// End for loop
And this is the result:
It has to be:
And so on.
Upvotes: 0
Views: 118
Reputation: 11
Do you have two times method "date.add(1, 'days')";
try this:
var date = moment($scope.dt);
for (var i = 0; i < parseInt($scope.numPagos); i++) {
var current = date.add(1, 'days');
$scope.resultados.push({
'numerodecuota' : i + 1,
'fechas' : current.format("MM/DD/YYYY"),
'pagos' : Math.round($scope.importeprestamo / $scope.numPagos + interes),
'interes' : Math.round(interes),
'capital' : $scope.importeprestamo / $scope.numPagos,
'fechaunix' : current.unix()
});
}// End for loop
Upvotes: 1
Reputation: 2944
Because you are adding one day twice in your code
Once here
'fechas': date.add(1, 'days').format("MM/DD/YYYY"),
Again Here
'fechaunix': date.add(1, 'days').unix()
Add only once. see the example
var app = angular.module("app", []);
app.controller("ctrl", function($scope) {
var date = moment();
$scope.numPagos="5";
$scope.resultados=[];
for (var i = 0; i < parseInt($scope.numPagos); i++) {
$scope.resultados.push({
'numerodecuota': i + 1,
'fechas': date.add(1, 'days').format("MM/DD/YYYY"),
//'pagos': Math.round($scope.importeprestamo / $scope.numPagos + interes),
//'interes': Math.round(interes),
//'capital': $scope.importeprestamo / $scope.numPagos,
'fechaunix': date.unix()
});
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
{{resultados}}
</div>
Upvotes: 1
Reputation: 3609
Note: It should be noted that moments are mutable. Calling any of the manipulation methods will change the original moment.
Looks like you're adding 1 day, and then adding another day for the fechaunix
date. Try just setting fechaunix
to date
once it's already been added:
$scope.resultados.push({
'numerodecuota' : i + 1,
'fechas' : date.add(1, 'days').format("MM/DD/YYYY"),
'pagos' : Math.round($scope.importeprestamo / $scope.numPagos + interes),
'interes' : Math.round(interes),
'capital' : $scope.importeprestamo / $scope.numPagos,
'fechaunix' : date.unix()
});
Upvotes: 3