9

angularFire の例では、firebase からオブジェクトのコレクションを取得する方法を示しています。

app.controller('ctrl', ['$scope', '$timeout', 'angularFireCollection',
  function($scope, $timeout, angularFireCollection) {    
    var url = 'https://ex.firebaseio.com/stuff';
    $scope.col = angularFireCollection(url);
  }
]);

単一のオブジェクトのみはどうですか?

私はこのようなことを試しました:

  fb.child('stuff/'+id).on('value', function(snapshot) {
    $scope.obj = snapshot.val();
    console.log('hey got the value')
    console.log(snapshot.val())
  });

うまくいかないようです。コンソールはオブジェクト値を正しく出力しますが、コントローラーは更新されません。

4

1 に答える 1

9

通常の angularFire サービスを使用して、単一のオブジェクトのタイプを指定してみてください。

app.controller('ctrl', ['$scope', '$timeout', 'angularFire',
  function($scope, $timeout, angularFire) {    
    var url = 'https://ex.firebaseio.com/stuff';
    angularFire(url, $scope, "obj", "");
  }
]);

4 番目の引数に注意してください (" " は文字列を意味し、ブール値、数値、オブジェクト、および配列も使用できます)。

于 2013-04-29T05:56:05.523 に答える