In my controller.js, I have an HTTP GET request that I have to call when my page loads and when a user pulls to refresh.
The way I'm doing it right now is by duplicating the $http code. Is there a way to make this more reusable? I can't figure out how to move it to my services.js file and reference it in my controller so that it runs.
.controller('GamesCtrl', function ($scope, $http) {
$http(
{
method: 'GET',
url: 'https://www.kimonolabs.com/api/dc6n4edu?apikey=U4SNiysE89aaLXSWRJgHKDZOByqSLM0p',
headers: {
'authorization': 'Bearer PW8V4OesZ61tCqSRNpXYtRn5ahcLdclU'
}
}).
success(function (data) {
$scope.data = data['results']['collection1'];
});
$scope.doRefresh = function() {
$http(
{
method: 'GET',
url: 'https://www.kimonolabs.com/api/dc6n4edu?apikey=U4SNiysE89aaLXSWRJgHKDZOByqSLM0p',
headers: {
'authorization': 'Bearer PW8V4OesZ61tCqSRNpXYtRn5ahcLdclU'
}
}).
success(function (data) {
$scope.data = data['results']['collection1'];
})
.finally(function() {
$scope.$broadcast('scroll.refreshComplete');
});
};
})