Difference between Firebase AngularFire implicit and explicit sync

All we need is an easy explanation of the problem, so here it is.

I am new to firebase. I want to build it with angularjs and I found angularfire.

In the angularFire docs listed
Implicit and explicit sync. I tried to understand the document in github but I still don’t understand what is the difference and how to use them.
angularFire() and angularFireCollection()

also, what are the arguments mean in angularFire() and angularFireCollection()?

thank in adv

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

Use angularFire if you want implicit sync, i.e. any changes made to your model will instantly propagate to all other clients (and vice versa).

Use angularFireCollection if you want to be in control of when any local data changes must be sent to the server. Any remote changes will still automatically update your local collection.

Implicit sync:

myapp.controller('MyCtrl', ['$scope', 'angularFire',
  function MyCtrl($scope, angularFire) {
    var promise = angularFire(url, $scope, 'items', []);
  }
]);

First argument is the location of the Firebase at which you want to store/retrieve data. Second argument is the scope, third argument is the name of the property under $scope you want the data bound as soon as the promise is fulfilled. For example:

promise.then(function() {
  // Data available in $scope.items
});

Fourth argument is the type of data you want in your JS object. Use [] for arrays, {} for objects, "" for strings, 1 for numbers and true for boolean. Note that if no data is present in the provided Firebase location you can also use this argument to set the default value.

In implicit sync if you want to make any changes, simply modify $scope.items and the change will automatically synchronize with all other clients via Firebase. Similarly, any changes made remotely will automatically update $scope.items.

Explicit sync:

myapp.controller('MyCtrl', ['$scope', 'angularFireCollection',
  function MyCtrl($scope, angularFireCollection) {
    $scope.items = angularFireCollection(url);
  }
]);

This method only takes one argument. If you want to add or remove items, use the add, remove or update methods. For example:

$scope.items.add({test: "object"});

Since angularFireCollection does not require a scope, you can also use this if you want to use Firebase outside of a controller (like angular directives, modules, etc.) Hope this helps!

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply