火力地堡AngularFire隐性和显性同步的区别 [英] Difference between Firebase AngularFire implicit and explicit sync

查看:133
本文介绍了火力地堡AngularFire隐性和显性同步的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的火力地堡。我想与angularjs构建它,我发现angularfire。

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

在列出的angularFire文档
隐性和显性的同步。我试图理解GitHub上的文档,但我还是不明白有什么区别,以及如何使用它们。
angularFire() angularFireCollection()

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()

也,有什么论据意味着 angularFire() angularFireCollection()

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

感谢在进阶

推荐答案

使用 angularFire 如果你想暗示同步,即你的模型所做的任何更改将立即传播到所有其他客户(反之亦然)。

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).

使用 angularFireCollection 如果你想在任何时候本地数据更改都必须发送到服务器的控制权。任何远程的变化仍然会自动更新本地收藏。

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.

隐式同步:

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
});

第四个参数是你的JS对象,你想要的数据类型。使用 [] 数组, {} 的对象,字符串, 1 数字和真正布尔。请注意,如果没有数据所提供的火力地堡的位置present你也可以使用此参数设置默认值。

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.

在隐含同步,如果你想进行任何更改,只需修改 $ scope.items 和改变,就会自动通过火力地堡所有其他客户端同步。同样,远程所做的任何更改都会自动更新 $ scope.items

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.

显式同步:

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"});

由于 angularFireCollection 不需要的范围,你也可以,如果你想使用火力地堡控制器之外使用(如角指令,模块等)希望这有助于!

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!

这篇关于火力地堡AngularFire隐性和显性同步的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆