I write my custom AngularJS filter, which should transform id to name, which will get from IndexedDb. I wrote this filter:
cardsList.filter('getCollectionName', ['IndexedDb', function(IndexedDb) {
return function(idCollection) {
var val = 'not';
IndexedDb.getById(IndexedDb.STORES.COLLECTION_STORE, idCollection).then(function(data) {
val = data.name; //here dont work return data.name;
}, function(err){
$window.alert(err);
});
return val; // here is still 'not'
}; }]);
So i have property val and i want set it with name of collection by id. But its return initial value 'not'. I knew that inside calling is not visible property val. But return data.name; inside succesful callback dont work. I looked at How do I return the response from an asynchronous call?, but I dont understood how fix my problem. How can I fix this so function return data.name from callback? Thanx