I am calling the controller to get the API value. How do I pass the array outside of the $http method?
I need to pass an array, pa[], to the $scope
If you prefer jQuery Ajax, use the extend function to return the success data outside,
$(function(){
$.extend({
returnData: function(url) {
var result = null;
var pa = [];
$.ajax({
url: url,
type: 'get',
dataType: 'jsonp',
async: false,
success: function(data) {
for (i = 0; i < data.feed.entry.length; i++) {
var entry = data.feed.entry[i];
pa.push(entry.gsx$productivity.$t);
}
result = pa;
}
});
return result;
}
});
});
finaldata = $.returnData('https://spreadsheets.google.com/feeds/list/0AsXjbsnPIu06dGswZUV4WX/values?alt=json-in-script&callback=angular.callbacks._0');
console.log(finaldata);