Receive data from a select in the Angular

0

I'm doing a select for a REST service, using Angular. But the page that should have the populated table with the data coming from select, goes blank.

In my page, I have an input and a button, which triggers the function that goes to the service and makes the select, so I'll send the record to another page. The data is returning, because in the callback of the js function, I start an alert on the screen, with the object returned, however, I can not popular my table with the select data. Would anyone know why? Thank you so much!

My js function that links to the service and does the select:

$scope.procurar = function (){
    var nome = $scope.filtro;
    $http.post(linkservice + "selectByNome", nome).then(function (response) {   
        $scope.nomes = response.data;
        alert($scope.nomes.texto_cnh);
        window.location.href = "resultadoBusca.jsp";
    });
}

My table should show the return data of the select:

<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 nomes">
    <td><a ng-click = "enviarDadosDetalhe(x)">{{x.id}}</a></td>
    <td><a ng-click = "enviarDadosDetalhe(x)">{{x.cpf}}</a></td>
    <td><a ng-click = "enviarDadosDetalhe(x)">{{x.texto_cnh}}</a></td>
    <td><a ng-click = "enviarDadosDetalhe(x)">{{x.data_validade_cnh}}</a></td>

    <td>
        <div ng-if ="x.status == 'a'">
            <button ng-click = "alterarstatus(x)"> Inativar Motorista</button>
            <button ng-click = "enviarDados(x)"> Atualizar motorista </button>
        </div>
        <div ng-if ="x.status == 'i'">
            <button ng-click = "alterarstatus(x)"> Ativar Motorista</button>
            <button ng-click = "enviarDados(x)"> Atualizar motorista </button>
        </div>

    </td>
</tr>

    
asked by anonymous 28.02.2017 / 01:28

1 answer

0
$scope.procurar = function (){
var nome = $scope.filtro;
$http.post(linkservice + "selectByNome", nome).then(function (response) {   
    $scope.nomes = response.data;
    alert($scope.nomes.texto_cnh);
    window.location.href = "resultadoBusca.jsp";
});

}

The response.data, were you able to print the text_cnh property? if it succeeded, the problem may be there, because your REST server is not returning an array, but a single object.

If you return a list, you can access the text_cnh property as it is below

$scope.procurar = function (){
var nome = $scope.filtro;
$http.post(linkservice + "selectByNome", nome).then(function (response) {   
    $scope.nomes = response.data;
    alert($scope.nomes[0].texto_cnh);
    window.location.href = "resultadoBusca.jsp";
});
    
01.03.2017 / 18:57