im trying to build an instagram feed app with ionic framework and i created a factory to handle my html requests so i can use them on my controllers, thing is, with instagram API, theres a value on the json array called next_url that i need to load the Older Photos/posts so: This is my factory:
app.factory('PersonService', function($http){
var BASE_URL = "https://api.instagram.com/v1/tags/sometag/media/recent?access_token=+++";
var items = [];
var nextUrl = 0;
return {
GetFeed: function(){
return $http.get(BASE_URL+'&count=10').then(function(response){
items = response.data.data;
**nextUrl = response.data.pagination.next_url;**
return items;
});
},
GetNewPhotos: function(){
return $http.get(BASE_URL+'&count=2').then(function(response){
items = response.data.data;
return items;
});
},
GetOldPhotos: function(){
return $http.get(**nextUrl**).then(function(response){
items = response.data.data;
return items;
});
}
}
});
I want to use the nextUrl = response.data.pagination.next_url; from GetFeed function to get the next_url and use it on the GetOldPhotos function that will use the nextUrl to load the older photos, i dont think i can return 2 values from the same function and i think $scope isnt an option in factory.
I know there could be more than one way to achieve this but i just started with ionic, angular, and javascript and im realy stuck here and would be great if i could get some "guidance" :D Sorry for any grammar, syntax, or any other error in this post and thank you in advance!
itemandnextUrlis in the factory, can't your code work without returning 2 of those?