AngularFire只更新一次

时间:2013-12-07 18:36:34

标签: angularjs 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 个答案:

答案 0 :(得分:0)

由于您在promise上下文中使用angularFire函数,因此continuation(then子句)仅运行一次并且对于初始数据。来自the docs

  

来自Firebase的数据是异步加载的,您可以使用承诺在服务器的初始数据加载时收到通知。

我怀疑你想要这样的东西:

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