Skip to content Skip to sidebar Skip to footer

$on Loaded Fires Once For New References AngularFire 0.5.0

Let's say were using pushState to navigate routes: $locationProvider.html5Mode(true); And there are two routes with two different controllers: $stateProvider.state('one', { url:

Solution 1:

This is due to the fact that locally cached data fires value events synchronously in Firebase.

On the first load, the server is contacted asynchronously by angularFire's _getInitialValue method. However, on the second load, since the value is already local, the broadcast event happens synchronously, and therefore before your $on('loaded'...) handler gets attached.

A couple thoughts come to mind: If the controllers are utilizing the same $firebase data, there should probably--in most common use cases--only be one. It should be moved to a service and shared accordingly.

Another workaround would be to store the loaded state in a service or in the $rootScope.

Ultimately, it should be corrected in angularFire so that the loaded event triggers even if the 'value' is already loaded synchronously.


Post a Comment for "$on Loaded Fires Once For New References AngularFire 0.5.0"