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
This really doesn't make a lot of sense. It should just be like this:
$scope.myData = [];
$http({
method: 'JSONP',
url: url
}).success(function (data) {
for (i = 0; i < data.feed.entry.length; i++) {
var entry = data.feed.entry[i];
$scope.myData.push(entry.gsx$productivity.$t);
console.log(pa); //[10,20,30,40,50]
}
});
Since pa was set inside of the controller function, it doesn't buy you anything to declare it and then set $scope.myData equal to pa. That's just asking for trouble.