0

I am having some problems moving my returned data from AngularFire2 into data structures within my code. The basics of simply getting a list of objects works for me, but I am trying to process a simpler list into an array.

My data in Firebase (V4.10.1, AngularFire2 V5.0.0-rc.6) is in

/teams/
    ABC:Team Name A
    DEF:Team Name B

My data is in the list as : format. I want to process this return data into a typescript array teamName['ABC'] = 'Team Name A'.

I am able to get the data and place it in the console.log() using: this.AfDb.list(Location).snapshotChanges().subscribe(console.log);

I have the problem when I try to process the data:

private Data_:{};

constructor(AfDb:AngularFirebaseDatabase) {
    const AfData:Observable<{}> = this.AfDb.list(Location).snapshotChanges();
    AfData.subscribe(list => {
            list.forEach(OneRec => {
                this.Data_[OneRec.key] = OneRec.payload.val();
            });
        });
}

I get an error that my Key value [OneRec.key]. core.js:1350 ERROR TypeError: Cannot set property 'ABC' of undefined.

I have tried using Data_:any; without success as well. I have recently turned on the TSLint functions in Ionic which is why I am trying to typedef all variables.

1 Answer 1

1

You've not initialized Data_ only set the type, thus it is undefined.

private Data_ = {};

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

1 Comment

True, but I still do not get an array of what I want. I am looking to populate the data into an array to use it with the key being the data from AngularFire2 and then the content, the results from AngularFire2.

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.