2013-12-07 114 views
1

爲什麼AngularFire只更新一次數據庫?AngularFire只更新一次

我得到了用戶,因爲這:

var firebaseURL = "https://.."; 

angularFire(new Firebase(firebaseURL), $scope, "database").then(function() { 
    $scope.user = $scope.database.users[0]; 
}); 

並在視圖:

<input ng-model="user.name" /> 

當我改變輸入,只更新一次,然後從來不會。

此外,如果我通過使用firebase ui更改了某些內容,則模型不會更新。

回答

1

由於您在承諾上下文中使用了angularFire函數,因此繼續(then子句)僅運行一次,並且僅用於初始數據。 From the docs

來自Firebase的數據是異步加載的,您可以使用承諾在來自服務器的初始數據加載時收到通知。

我懷疑你想這樣的事情:

angularFire(new Firebase(firebaseURL), $scope, "database"); 
$scope.$watch("database[0]", function (newVal) { 
    $scope.user = newVal; 
}); 
+0

謝謝,我發現這個解決方案較早,實現了它和它的作品。 –