ng-repeat angular

Asked

Viewed 710 times

1

I am developing an application with a GRID and I needed to format the dates coming to this GRID using data filter angular.

However I am not being able to print the date array inside the tag <div>, if I put to print in a <tr> or <td> works, but I’m already using a ng-repeat in <tr>, 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 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);
});
  • The date you want to use in a separate column, it is part of the object registros? Or is an array a part, as its controller?

  • @Celsomtrindade So I tried it both ways, actually, at first, it was a separate array, but I thought I’d put cmo object in records, to use a single ng-repeat, but still, the column is empty

1 answer

1

Your question is not very clear, and it would be much better if you could show an example of the content of $scope.registros and $scope.data. Still, follows a simplified example of visualization:

<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" ng-click="enviarDadosDetalhe(x)">
    <td>{{x.nome}}</td>
    <td>{{x.cpf}}</td>
    <td>{{x.rg}}</td>
    <td>{{x.texto_cnh}}</td>
    <td>
        <table>
            <tr ng-repeat='y in x.datas'>
                <td>{{y}}</td>
            </tr>
        </table>
    </td>
</tr>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.