Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

92
Visualizações
Custom Service not giving desired result in controller in AngularJS 1.8

I have to debug a snippet written in AngularJS.


//===== service ==
app.service('allUserService', function($http) {

    var config = {
        headers: {
            'X-XSRF-TOKEN': gettingValueFromSomewhere()
        }
    };


        this.getAll = function() {
            var restUrl = CONTEXT_PATH + '/rest/path/mypath';
            
             return $http.get(restUrl, config).then(function(response) {
            console.log(response.data.body); // console prints an Array which is correct
                return response.data.body;
            });
        }

});

//========= controller ====
app.controller('UserCtrl', function($scope,allUserService) {
            var valueArray = [];
            valueArray = allUserService.getAll();
            console.log(valueArray);
            $scope.faqBook = valueArray; 
          
         });

allUserService :I am getting correct result from Rest webservie and console log shows desired return (an Array)

faqUserCtrl : I am not getting desired value in console log. Pls help me in finding the issue. It should have an array. I am expecting an Array in $scope.faqBook.

Important to Note, when I return a hardcoded array from allUserService, the code works fine

<div class="container" ng-app="UserModule" ng-controller="UserCtrl">

  <p>Search : <input type="text" ng-model="search"/></p>
    
<table id="mainTable" class="table table-striped table-hover">
  <tr ng-repeat="x in faqBook | filter:search">

    <td><ul class="list-group"><li class="list-group-item">Question: {{ x.question }}</li><li class="list-group-item"> Answer: {{ x.answer }}</li></ul></td>

  </tr>
</table> 
</div>
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda