AngularFire provides event handlers for "loaded" and "modified" events. From annotated source :
object.$on = function(type, callback) { switch (type) { case "change": self._onChange.push(callback); break; case "loaded": self._onLoaded.push(callback); break; default: throw new Error("Invalid event type " + type + " specified"); } };
So you should be able to do something like this:
var ref = new Firebase('myfirebaseurl'); $scope.data = $firebase(ref); $scope.data.$on('loaded', function(){ if($scope.data.desiredProperty) { doSomething(); } });
Edit:
It appears that when the AngularFire loaded event is fired, the $scope.data object is not yet fully populated. This seems to be a known issue, but there are some ways around it.
Data access as a parameter to the loaded callback function:
$scope.data.$on("loaded", function(data) { console.log(data); }
Skip AngularFire and click directly on the Firebase API:
ref.on("value", function(data) { console.log(data.val()); }
ajk
source share