Handle Firebase data in controller with angular 1

Asked

Viewed 296 times

0

I’m working with Angular 1, Angularfire and Firebase. I made the following call that returns the following data:

var _refLista = firebase.database().ref()
$scope.lista = $firebaseObject(_refLista.child('listas').child(idLista))
console.log($scope.lista);

In the console the data appears structured as follows:

{
    nome: "nome da lista",
    usuarios: [0:"OkJiuyhTfrdgF", 1:"kjIugYHTkiuh"]
}

In the view I can print out everything by certifying, example:

{{ lista.nome }}
{{ lista.usuarios }}

But when I try to access $Scope.lista.users in the controller the result is always Undefined.

Can anyone help?

1 answer

1


You have loaded an object from the "$firebaseObjec" it returns a Javascript object that contains the Firebase data with some additional and specific Angularfire fields, this object may not be available completely because of asynchronous loading, use the $Loaded() function to load the example object:

   $scope.lista = $firebaseObject(_refLista.child('listas').child(idLista))
   $scope.lista.$loaded().then(function (res) {           
       //AQUI VOCÊ PODE LER AS PROPRIEDADES
       console.log("Minha lista",lista.usuarios)             
   })  

Browser other questions tagged

You are not signed in. Login or sign up in order to post.