I'm developing an application with a GRID and I needed to format the dates coming to this GRID using data filter
of Angular.
But I'm not able to print the date array inside the <div>
tag, if I put it to start with a <tr>
or <td>
it works fine, but I'm already using a ng-repeat in <tr>
, you would need another ng-repeat only for a given column.
My html:
<table>
<tr>
<th>Nome</th>
<th>C.P.F</th>
<th>CNH</th>
<th>Categoria</th>
<th>Vencimento</th>
</tr>
<tr ng-repeat="x in registros | filter : filtro">
<td><a ng-click = "enviarDadosDetalhe(x)">{{x.nome}}</a></td>
<td><a ng-click = "enviarDadosDetalhe(x)">{{x.cpf}}</a></td>
<td><a ng-click = "enviarDadosDetalhe(x)">{{x.rg}}</a></td>
<td><a ng-click = "enviarDadosDetalhe(x)">{{x.texto_cnh}}</a></td>
<td><a ng-click = "enviarDadosDetalhe(x)">{{x.datas[$index]}}</a></td>
<tr ng-repeat = "y in data track by $index">
<td>{{y | date : "dd/MM/yyyy"}}</td>
</tr>
</tr>
My function that returns the records in the controller:
$http.get(linkservice + "select").then(function (response) {
$scope.registros = response.data;
$scope.data = [];
for(var i = 0; i < $scope.registros.length; i++){
var data = new Date($scope.registros[i].data_nascimento);
$scope.data.push(data);
}
$scope.registros.datas = $scope.data;
console.log($scope.registros);
});