When making a request to the 500px API using $http
for popular photos, the response object is successfully returned. However, I am facing difficulty in pushing the retrieved photo items to the view.
Below is my current controller code:
meanApp.controller 'SearchController', ['$scope', '$http', 'Global', ($scope, $http, Global) ->
$scope.global = Global
$scope.photos = []
$scope.submit = ->
if $scope.text
$http.get("https://api.500px.com/v1/photos?feature=popular").success (data) ->
$scope.photos.push data
]
The JSON response object looks like this (excerpted for conciseness):
{
"current_page":1,
"total_pages":1449,
"total_items":7244,
"photos":[
{
"id":58494612,
"user_id":1795149,
"name":"Van Gogh!!!!"
},
{
"id":49566952,
"user_id":1795149,
"name":"Autumn touch!"
},
{
"id":49527034,
"user_id":2670757,
"name":"Untitled"
},
{
"id":39374598,
"user_id":3669660,
"name":"The Wild Cannot Be Tamed Nor The Rednecks in it! "
},
{
"id":28303657,
"user_id":2843749,
"name":"Main road to go to the moon"
}
]
}
This is the structure of my view:
<h1>Photo search</h1>
<form ng-submit="submit()" ng-controller="SearchController">
Enter text and hit enter:
<input type="text" ng-model="text" name="text">
<input type="submit" id="submit" value="Submit">
</form>
<ul>
<li ng-repeat="photo in photos.photos">{{photo.name}}</li>
<li ng-hide="photos.length">No photos</li>
</ul>
Currently, the list within the <ul>
tag does not update as expected. I have considered using $apply
, but that did not solve the issue either.