1

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?

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.