My Code is:
$rootScope.getResource = function(id) {
$http.get( "path/of/resource/" + id )
.success(function (data, status, header, config) {
return data;
})
.error(function (data, status, header, config) {
console.log("Error");
});
But it always returns 'undefined'.
I know the problem is the $http function is asynchronous and I should use promises, but I can't figure out how to do everything inside just a function in $rootScope.