I am having trouble displaying the items a user has bookmarked.
The code to get the bookmarks is as follows:
app.factory('API', function($firebaseArray, $firebaseObject, FBURL, $q) {
var ref = new Firebase(FBURL);
/*
Called to retrieve the list of items bookmarked
*/
API.getBookmarks = function(userID) {
var defer = $q.defer();
var query = ref.child('Users').child(userID).child('bookmarkedItems');
$firebaseArray(query).$loaded(function(data) {
var bookmarks, i, itemKey;
i = 0;
bookmarks = {};
while (i < data.length) {
itemId = data[i].$id;
bookmarks[itemKey] = API.getSingle(itemId);
i++;
}
defer.resolve(bookmarks);
});
return defer.promise;
};
/*
Called to retrieve the items in the bookmark list
*/
API.getSingle = function(itemId) {
var defer = $q.defer();
var query = ref.child('Items').child(itemId);
$firebaseObject(query).$loaded(function(data) {
defer.resolve(data);
});
return defer.promise;
};
return API;
});
The trouble is that API.getBookmarks('someUserId') is returning me a list of promises attached to each item.$id instead of the items' data. So, the problem arises from my use of asycnhronous functions, but it appears that I am using defer and $loaded in the proper places to deal with these issues.
Does anyone have an idea of how to fix it?
Also, not entirely relevant, but I want to note that this operation worked perfectly fine before I just updated from AngularFire 0.9x to 1.1.1, and the changelog notes some issues with the firebaseArray $loaded function resolving before it should.