I have a problem with my angular code and I can't figure out where's it's from.
I want to return the result json of my api call, I DONT want a promise or anything I want the json result of the $http service.
When i'm outside of the $http my variable result is set to 'undefined' but inside the $http service it's set to the result of the json.
angular.module('app')
.factory("Content", function ContentFactory($http) {
return {
all: function () {
var result;
$http.get('wp-json/acf/post/2').success(function(res){
result = res.acf;
console.log(result); // 'Object'
});
console.log(result); // 'undefined'
return result;
},
};
});