In the context of my Angular application, I am facing a requirement where the method getData() must consistently return a promise. Should data be present in local storage and not null, it should be returned as a promise without requiring the $http.get function to be invoked.
How can this functionality be implemented?
getData() {
var data = localStoradge.getItem('data');
if (data == null) {
return $http.get('url').then(function(response){
data = response;
return data
})
}
}