I'm trying to return the values I get in my $http.get but I can't get it to work...
$scope.getDecision = function(id) {
var defer = $q.defer();
$http({
method: 'GET',
url: 'http://127.0.0.1:3000/decision',
params: {id: id},
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function(data, status, header, config) {
console.log(data); //----> Correct values
defer.resolve(data);
}).error(function(data, status, header, config) {
defer.reject("Something went wrong when getting decision);
});
return defer.promise;
};
$scope.selectView = function(id) {
var decision = $scope.getDecision(id);
console.log(decision); //----> undefined
}
When I call selectView I want to get a decision, but all I get is undefined... Have I misunderstood the promise pattern? :S