I am trying to call a web service using ajax and then pass the results to an angular controller. I cannot get the values out of the callback function to pass into a scope variable. I think it's just my bad understanding of how the callback function works.
here is the code:
function ajaxKimono(callback) {
$.ajax({
url:"https://www.kimonolabs.com/api/cveeggn4?apikey=NWYzkeJpFDtb4aOYd6yD96L5PdLuZHjo",
crossDomain: true,
dataType: "jsonp",
success: callback,
error: function (xhr, status) {
//handle errors
console.log(xhr);
console.log(status);
}
});
};
angular.module('app').controller('gifCtrl', function(){
var self = this;
var gifs = [];
ajaxKimono(function(result){
var collection = result.results.collection1;
$.each(collection, function(i, item){
gifs.push({ gif: item.property5.href});
});
//this outputs the correct data
//so i know the ajax call is working correctly
console.log(gifs);
self.gifCollection = gifs;
});
//something about the scope is messing me up
//this outputs nothing...
console.log(self.gifCollection);
});