Receive data from a select in Angular

Asked

Viewed 304 times

0

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

On my page, I have an input (To enter the driver’s name) and a button, which triggers the function that goes to the service and makes the select, so I send the registration to another page. The data is coming back, because in the js function callback, I print an Alert on the screen, with the returned object, however, I can’t popular my table with the select data. Would anyone know why? Thank you very much!

My js function that links to the service and makes 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 that should show the return data from 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>

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";
});

}

Sponse.data, have you managed to print the property texto_cnh ? if successful, 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 in the way 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";
});

Browser other questions tagged

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