Difference Between Firebase AngularFire Implicit and Explicit Sync

I am new to firebase. I want to build it using angularjs and I found the corner fire.

In the angular plans given in the document, Implicit and explicit synchronization. I tried to understand the document on github, but I still don't understand what the difference is and how to use them. angularFire() and angularFireCollection()

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

thanks in adv

+6
source share
1 answer

Use angularFire if you need implicit synchronization i.e. Any changes made to your model will instantly apply to all other customers (and vice versa).

Use angularFireCollection if you want to control when any local data changes should be sent to the server. Any deleted changes will continue to automatically update your local collection.

Implicit synchronization:

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

The first argument is the location of Firebase where you want to store / retrieve data. The second argument is the scope, the third argument is the name of the property under $ scope that you want to associate with the data as soon as the promise is fulfilled. For instance:

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

The 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. Please note: if no data is provided in the provided Firebase location, you can also use this argument to set the default value.

In implicit synchronization, if you want to make any changes, just change $scope.items , and this change will be automatically synchronized with all other clients through Firebase. Similarly, any changes made remotely will be automatically updated by $scope.items .

Explicit synchronization:

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

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

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

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

+19
source

Source: https://habr.com/ru/post/945770/


All Articles