You can use the angular date filter or a manipulation of dates library like moment.js
Using the date filter you can pause your date both in the view and in the controller but this has the disadvantage that this filter expects your entry date to come as type Date or as a string in the format ISO 8601 .
Your dates come in a dd-MM-yyyy
format, which is not a standard so you can use string manipulation or regular expressions to achieve the desired effect as long as the input format does not change. Here is an example.
angular.module('app', [])
.controller('MyCtrl', function($scope, $filter) {
var fechaInicio, fechaFin;
$scope.fechas = [{
"fechaInicio": "01-04-2016"
}, {
"fechaFin": "05-08-2016"
}];
var parseDate = $filter('parseDate');
for (i = 0; i < $scope.fechas.length; i++) {
fechaInicio = parseDate($scope.fechas[i].fechaInicio);
fechaFin = parseDate($scope.fechas[i].fechaFin);
alert(fechaInicio);
alert(fechaFin);
}
})
.filter('parseDate', function() {
return function(input) {
var result = input;
var format = /^(\d{2})-(\d{2})-(\d{4})$/;
var match = format.exec(input);
if (input && match) {
result = match[3] + '-' + match[2] + '-' + match[1];
}
return result;
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="MyCtrl">
<ul ng-repeat="fecha in fechas">
<li>Fecha inicio: {{fecha.fechaInicio | parseDate }}</li>
<li>Fecha fin: {{fecha.fechaFin | parseDate }}</li>
</ul>
</div>
Here I leave another using moment.js which in my opinion is more complete since you can easily modify it in the future to any other input format.
angular.module('app', [])
.controller('MyCtrl', function($scope, $filter) {
var fechaInicio, fechaFin;
$scope.fechas = [{
"fechaInicio": "01-04-2016"
}, {
"fechaFin": "05-08-2016"
}];
for (i = 0; i < $scope.fechas.length; i++) {
fechaInicio = moment($scope.fechas[i].fechaInicio, 'DD-MM-YYYY').format('YYYY-MM-DD');
fechaFin = moment($scope.fechas[i].fechaFin, 'DD-MM-YYYY').format('YYYY-MM-DD');
alert(fechaInicio);
alert(fechaFin);
}
})
.filter('parseDate', function() {
// Lo mismo en un filtro
return function(input) {
var result = input;
if (input) {
result = moment(input, 'DD-MM-YYYY').format('YYYY-MM-DD');
}
return result;
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="http://momentjs.com/downloads/moment.min.js"></script>
<div ng-app="app" ng-controller="MyCtrl">
<ul ng-repeat="fecha in fechas">
<li>Fecha inicio: {{fecha.fechaInicio | parseDate }}</li>
<li>Fecha fin: {{fecha.fechaFin | parseDate }}</li>
</ul>
</div>