Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

91
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!