I am using angularjs and I cannot force the next controller to save the $ scope variable the data returned from the AJAX request to Flickr. $http.get makes a call to a locally stored json file. After success, it uses the json returned in success() to determine the appropriate URL to call the Flickr AJAX API. After the success of this call, I am logging data on the console. So far so good, it returns an array of three objects. However, I am trying to set this array to the $ scope ( $scope.photos ) variable so that I can $scope.photos over my view template. However, when I try to output {{photos}} in html, there is nothing. I suspect this is a promise problem, and the template is rendering before AJAX returns the data from Flickr, but I go through the docs without any frills (looked a bit at $q ). I am a little new to Angular and will be grateful for your understanding. Thanks!
artistControllers.controller('PhotoController', ['$scope', '$http', '$routeParams', '$q', function ($scope, $http, $routeParams, $q){ $http.get('js/data.json').success(function(data){ $scope.artists = data; $.ajax({ type : "GET", dataType : "jsonp", url : $scope.artists[$routeParams.itemId].flickr, success: function(flickr){ $scope.photos = flickr.items; console.log($scope.photos); } }); }); }]);
source share