Skip to content

How do I iterate through FirebaseListObservable<[]> object #682

@sean-hill

Description

@sean-hill

Version info

Angular: 2.1.0

Firebase: 3

AngularFire: 2.0.0-beta.6

Other (e.g. Ionic/Cordova, Node, browser, operating system): Ionic

How to reproduce these conditions

Steps to set up and reproduce

Say I subscribe to a list of items:

this.items = this.af.database.list('items');

And I add to these items in another function:

this.items.push({ im: 'cool' });

Then in another function I'd like to iterate through my items:

this.items.forEach(item => {
    console.log('Item:', item);
});

Expected behavior

I expect console.log(item) to print out $ Item: { im: 'cool' } but instead it prints out an array for each time I added to the items list.

Actual behavior

The whole array is printed multiple times:

$ Item: []
$ Item: [{ im: 'cool' }]
$ Item: [{ im: 'cool' }, { again: 'yep' }]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions