Pregunta

In the angularFire examples it shows how to get a collection of objects from firebase.

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

What about a single object only?

I tried something like this:

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

Doesn't seem to work. The console outputs the object value correctly but the controller doesn't update.

¿Fue útil?

Solución

Try using the regular angularFire service, and specifying the type of your single object:

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

Note the 4th argument (" " means string, you can also use booleans, numbers, objects and arrays).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top