title: Custom Service not giving desired result in controller in AngularJS 1.8
body: <p>I have to debug a snippet written in AngularJS.</p>
  <pre><code>
  //===== 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; 
            
           });
  </code></pre>
  <p><strong>allUserService</strong> :I am getting correct result from Rest webservie and console log shows desired return (an Array)</p>
  <p><strong>faqUserCtrl</strong> : 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.</p>
  <p><strong>Important</strong> to Note, when I return a hardcoded array from <strong>allUserService</strong>, the code works fine</p>
  <pre><code>&lt;div class=&quot;container&quot; ng-app=&quot;UserModule&quot; ng-controller=&quot;UserCtrl&quot;&gt;
  
    &lt;p&gt;Search : &lt;input type=&quot;text&quot; ng-model=&quot;search&quot;/&gt;&lt;/p&gt;
      
  &lt;table id=&quot;mainTable&quot; class=&quot;table table-striped table-hover&quot;&gt;
    &lt;tr ng-repeat=&quot;x in faqBook | filter:search&quot;&gt;
  
      &lt;td&gt;&lt;ul class=&quot;list-group&quot;&gt;&lt;li class=&quot;list-group-item&quot;&gt;Question: {{ x.question }}&lt;/li&gt;&lt;li class=&quot;list-group-item&quot;&gt; Answer: {{ x.answer }}&lt;/li&gt;&lt;/ul&gt;&lt;/td&gt;
  
    &lt;/tr&gt;
  &lt;/table&gt; 
  &lt;/div&gt;
  </code></pre>