I have a service which exposes some utilities methods that are executed using $http
// my service declaration
// $http gets injected
this.getName = function(){
$http(options)
.then(
function(data){
return data;
},
function(error){
return 'some error';
}
);
};
this.getAge = function(){
$http(options)
.then(
function(data){
return data;
},
function(error){
return 'some error';
}
);
};
In my controllers, I get this service injected in order to expose those utilities methods such as:
// my controller declaration
var service = $injector.resolve('$myService');
Then, from here I want to call the utilities methods such as:
console.log(service.getName());
or do something like
if(service.getName() == ''){
}
The problem is that when I try to do that, the method start the async HTTP call and returns empty, while only later the answer is returned. How can I address this issue?