ArtK
ArtK

Reputation: 1185

Getting value from Firebase list response array

I'm trying to get element values from response to list() method when accessing Firebase realtime database. I must have some outdated documentation so the answer may be super easy for someone with basic experience in TypeScript and Firebase.
It starts like this: I have object db: AngularFireDatabase
I call db.list('/firebaseElements').snapshotChanges().subscribe(elements=>{let els = elements; ...})
If I JSON.stringify(els) I get [{"payload":"element1","type":"value","prevKey":null,"key":"1"},{"payload":"element2","type":"value","prevKey":"1","key":"2"},{"payload":"element3","type":"value","prevKey":"2","key":"3"}]
So if I call els[0].payload I should get element3 string. element3 is a leaf in that database so it is a simple string value. However, if I access payload it turns out to be an object with 2 properties _database and _delegate. My old documentation also references accessing value by els[i].$value property but that doesn't seem to be working either.
Hence my question: how do you access simple (leaf) values from nodes retreived from Firebase database?

Upvotes: 1

Views: 76

Answers (1)

ArtK
ArtK

Reputation: 1185

Well, all I had to do was to subscribe to valueChanges() and not snapshotChanges() and then I get leaf values straight away. My bad.

Upvotes: 1

Related Questions