Printing Flickr Api Response To Console Angularjs
I'm currently trying to make the API call work and want to see if it has managed to return the API data from the external source. How do I print an output to the console from the
Solution 1:
This actually works a bit differently. You will have to define the callback function jsonFlickrFeed. Check the code below.
You will notice two things here:-
- We're requesting the data with parameter ?format=json. Check the response here.
- You'd notice that the response coming out is looking for a callback function jsonFlickrFeed. Just define the handler for data into this function and there we go.
var app = angular.module('imageViewer', ['ng', 'ngResource']);
app.controller('AppGallery',[ '$scope','$http', functionAppGallery($scope, $http) {
$http.jsonp('https://api.flickr.com/services/feeds/photos_public.gne?format=json').success(function (data) {
});
jsonFlickrFeed = function(data){
$scope.data = data;
console.log(data);
}
}]);
<!DOCTYPE html><htmlng-app="imageViewer"><head><title>Photo Viewer</title><scriptsrc="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.12/angular.js"></script><scriptsrc="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.12/angular-resource.js"></script><scriptsrc="js/app.js"></script></head><bodyng-controller="AppGallery">
{{data}}
</body></html>
Check here and for more information.
If you're using jQuery you can use jQuery.getJSON instead. More details regarding jQuery.getJSON .
Hope this helps! Please mark as answer if it does! Thanks!
Solution 2:
To avoid using jsonp, add the following query parameter:
&nojsoncallback=1
Post a Comment for "Printing Flickr Api Response To Console Angularjs"