I'm trying to share data via a service that uses the $HTTP function between controllers. I'm trying to pass the return data in SUCCESS to another controller. Something is wrong I think in the service the data doesn't get to the second controller. below is my code can someone take a look at it and tell me what I'm doing wrong point me to the right direction on what to do.
services.js
.factory('userService', function ($http) {
var url = "url.php";
var headers = {
'Content-Type' : 'application/x-www-form-urlencoded; charset-UTF-8'
};
var params = "";
return {
getUsers : function (entry, searchTypReturn) {
params = {
entry : entry,
type : searchTypReturn,
mySecretCode : 'e8a53543fab6f5e'
};
return $http({
method : 'POST',
url : 'https://servicemobile.mlgw.org/mobile/phone/phone_json.php',
headers : {
'Content-Type' : 'application/x-www-form-urlencoded; charset-UTF-8'
},
transformRequest : function (obj) {
var str = [];
for (var p in obj)
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
return str.join("&");
},
data : params
})
.success(function (data, status, headers, config) {
return data;
});
}
}
})
controller.js
.controller('phoneController', function ($scope, md5, $http, userService, $ionicLoading, $location, $ionicPopup) {
userService.getUsers(form.entryText, searchTypReturn).success(function (data, status, headers, config) {
$ionicLoading.hide();
$scope.name = data.PlaceDetailsResponse.results[0].first_name;
if ($scope.name == 0) {
$scope.showAlert();
} else {
$location.path('phoneView');
$ionicLoading.hide();
}
}).error(function (data, status, headers, config) {
$scope.showAlert();
$ionicLoading.hide();
})
});
.controller('phoneViewController', function ($scope, userService) {
$scope.input = userService;
console.log('This is from phoneView', $scope.input);
});
then()to return data from promise object