I have a function like this:
$scope.doesUserLike = function(entryID, userID) {
var userLike = false;
$scope.likesRef.on('value', function(snap) {
snap.forEach(function(like) {
if(like.val().entryID == entryID && like.val().userID == userID) {
userLike = true;
console.log(userLike);
}
});
});
console.log(userLike);
return userLike;
}
The console outputs true
inside of the foreach loop but outside of the foreach loop it outputs false
, I also tried $scope.userLike
with the same result.