JavaScript How to return object from angularJS service AFTER http request is complete? return object from array,return object from arrow function,return

I'm implementing a small service for my angularJS app that makes an http request to my server for a couple of text posts. Here's my current implementation:

app.factory("postFetcher", ['$http', function($http){
  var posts; 

  $http.get('https://cdn.contentful.com/spaces/k2mwszledbge/entries?access_token=afa8ba8572bb0232644d94c80cfd4ae01314cd0589b98551147aab50f7134e30')
    .then(function(response){
      posts = response.data.items;
    });

  return {
    getList: function(){
      return posts; 
    }
  }
}]);

The problem with this is that the http request is not complete by the time that the posts array is returned. My intuition tells me to place the return function within the http .then function so that it is only returned once the request is complete, however this isn't allowed.

Is there a way I can delay the return of posts until the http request is complete?

Answer:1

Is it possible to have the X axis in the middle of the graph? When having Y values both negative and positive - and the X axis is on the 0 value lets say similar to this image

Is it possible to have the X axis in the middle of the graph? When having Y values both negative and positive - and the X axis is on the 0 value lets say similar to this image

I'm migrating a complex map from V2 to V3. The user can digitize polygons and polylines. In V2 getting a high contrast strokeColor was as easy as: var strokeColor = GMap.getCurrentMapType()....

I'm migrating a complex map from V2 to V3. The user can digitize polygons and polylines. In V2 getting a high contrast strokeColor was as easy as: var strokeColor = GMap.getCurrentMapType()....

I have a pop window which contains jQuery from to datepicker. I'm not able to select the End date value. jQuery call $(function() { $("#createdFromDate").datepicker( { defaultDate : "+...

I have a pop window which contains jQuery from to datepicker. I'm not able to select the End date value. jQuery call $(function() { $("#createdFromDate").datepicker( { defaultDate : "+...

  1. jquery datepicker from and to date
  2. jquery datepicker from and to date validation
  3. jquery datepicker from current date
  4. jquery datepicker from to
  5. jquery datepicker from today
  6. jquery datepicker from date to date example
  7. jquery datepicker from to validation
  8. jquery datepicker from to range
  9. jquery datepicker from to example
  10. jquery datepicker from button
  11. jquery datepicker from icon
  12. jquery datepicker with time
  13. jquery datepicker on change
  14. jquery datepicker with month and year selection
  15. jquery datepicker on select
  16. jquery datepicker in angular 4
  17. jquery datepicker in angular 6
  18. jquery datepicker in mvc
  19. jquery datepicker in asp.net
  20. jquery datepicker on select event

I can simulate text selection with protractor by a lot of different ways. But I can't find solution how I can expect that text was really selected. How I can do this without using marking? I can ...

I can simulate text selection with protractor by a lot of different ways. But I can't find solution how I can expect that text was really selected. How I can do this without using marking? I can ...