Inside my controller I need a function that takes a parameter and returned a URL from server. Something like this:
$scope.getPoster = function(title) {
return $http.get("http://www.omdbapi.com/?t=" + title + "&y=&plot=short&r=json");
};
And inside my view I need to pass the title this way and get result as src for ng-src:
<div class="col-sm-6 col-md-3" ng-repeat="movie in movies">
<div class="thumbnail">
<img class="poster" ng-src="{{getPoster(movie.Title)}}" alt="{{movie.Title}}">
<div class="caption">
<h3>{{movie.Title}}</h3>
<p>{{movie.Owner}}</p>
</div>
</div>
</div>
I know the HTTP communications on $http never ever return data that I need immediately because all communications are asynchronous So I need to use promise:
$scope.getPoster = function(title) {
$http({ url: "http://www.omdbapi.com/?t=" + title + "&y=&plot=short&r=json" }).
then(function (response) {
// How can I return response.data.Poster ?
});
};
So my question is that How can I return the response as result for getPoster function?
Any idea?
return responde.data.Poster