I have a problem with the service to come back from a singular view again ajax and refreshes the view I tested with “promises” but I get nothing
.factory('AleatoryPhotos', function($http, $q, $ionicLoading, $state, $ionicPopup) {
var photos = null;
var tags = null;
var retrieve = function() {
var deferred = $q.defer();
$http({
method: 'POST',
url: restServer,
data: "funcion=" + "__getRandomImages&token=" + localStorage.getItem("token") + "&userId=" + localStorage.getItem("userId") ,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}).success(function(data, status, headers, config) {
if (data.resp == 'denied'){
deferred.reject();
localStorage.removeItem("token");
localStorage.removeItem("userId");
$state.go('login');
$ionicPopup.alert({
template: '<div class="popcontent"><div class="popcolor"><span class="icon-stack"><img width="80" src="img/phone.png"/></span></div><div id="poptitle">logged into another device<div><p>this device has no internet connection, connect it and try it later</p></div>'
}).then(function(res) {
});
}else{
deferred.resolve(data);
photos = data;
tags = data;
}
}).error(function(data, status, headers, config) {
});
return deferred.promise;
}
return {
all: retrieve,
get: function(idPost) {
return photos[idPost];
},
gettags: function(idPost) {
return tags[idPost];
}
}
})