AngularFire 绑定到范围 vs $bindTo?

AngularFire binding to scope vs $bindTo?

在 angular fire documentation 中,这是我试图理解的两行:

 // To make the data available in the DOM, assign it to $scope
     $scope.data = obj;

 // For three-way data bindings, bind it to the scope instead
     obj.$bindTo($scope, "data");

他们在做同样的事情吗?是否都绑定到 3 向数据绑定的范围?

不,他们不是在做同样的事情。那将是一个非常愚蠢的 API。 :-)

运行 $scope.data = $firebaseObject(ref) 将 Firebase 位置中的数据绑定到范围。对 Firebase 数据库中数据的任何更新都会自动反映在范围中,因此 - 如果您将 HTML 元素绑定到 $scope.data - 也会在屏幕上更新。流程是单向的:从数据库到屏幕。

调用 obj.$bindTo($scope, "data") 两者都将 Firebase 位置中的数据绑定到范围 监听对 $scope.data 的更改,然后将其发送回 Firebase数据库自动。所以这创建了一个双向、三向绑定。 HTML中的更新被发送到数据库,数据库中的更新被发送到屏幕。

这一切都有很好的记录,例如在这个博客 post "Three-Way Data Binding with Firebase and Angular". The regular AngularFire documentation also contains a good section about three-way data binding.