Angularfire: FirebaseObjectObservable snapshot - Loop through field names?

Created on 28 Apr 2017  路  3Comments  路  Source: angular/angularfire

Is there a way to loop through the field names (not values) of a FirebaseObjectObservable snapshot?

Thank you.

this.contact = this.angularFire.database.object('contacts/' + this.contactId);
      this.contact.subscribe(contactSnapshot => {
        // Loop through Field Names or place then into an Array?
        console.log('field name:  ', contactSnapshot.fieldNames);
})

Most helpful comment

@Sun3 You must use this only for repo issues for question please use stackoverflow,

still to give you an idea please review below:

this.contacts = af.database.list('/contacts', { preserveSnapshot: true });
this.contacts
  .subscribe(snapshots => {

//let mycontacts = [];

    snapshots.forEach(snapshot => {
      //console.log(snapshot.key)
      //console.log(snapshot.val())
}

//this.mycontacts.push(snapshot.key);

});

All 3 comments

Hi @Sun3 this type of question would be better asked on StackOverflow. Github issues are usually reserved for bug reports and feature requests, and not general how-to questions.

Will do thanks. I looked at the API but could not see a way to do it and would love to see this feature.

@Sun3 You must use this only for repo issues for question please use stackoverflow,

still to give you an idea please review below:

this.contacts = af.database.list('/contacts', { preserveSnapshot: true });
this.contacts
  .subscribe(snapshots => {

//let mycontacts = [];

    snapshots.forEach(snapshot => {
      //console.log(snapshot.key)
      //console.log(snapshot.val())
}

//this.mycontacts.push(snapshot.key);

});
Was this page helpful?
0 / 5 - 0 ratings