angularfire2: Type 'Observable' is no

2019-07-10 16:59发布

问题:

Hi im new at angularfire2. Im trying to connect objects to an array (list) based on $key values.

my current code looks like:

console.log("Create Relationship Person 2 Person Observable");
        const relationshipP2Ps$: FirebaseListObservable<any>  = af.database.list('/relationshipP2P') // Primary list
            .map(items => {
                // `items` is an array of all items at the moment
                for (let item of items) {
                    // Find each corresponding associated object and store it as a FibrebaseObjectObservable
                    const i: FirebaseObjectObservable<any> = af.database.object('/person/' + item.person1, { preserveSnapshot: true })
                    i.subscribe(snapshot1 => {
                        console.log(snapshot1.key)
                        item.person1FirstnameEng = snapshot1.val().firstnameEng;
                        item.person1LastnameEng = snapshot1.val().lastnameEng;
                        item.person1FirstnameZhs = snapshot1.val().firstnameZhs;
                        item.person1LastnameZhs = snapshot1.val().lastnameZhs;
                    });
                    const j:FirebaseObjectObservable<any> = af.database.object('/person/' + item.person2, { preserveSnapshot: true })
                    j.subscribe(snapshot2 => {
                        console.log(snapshot2.key)
                        item.person2FirstnameEng = snapshot2.val().firstnameEng;
                        item.person2LastnameEng = snapshot2.val().lastnameEng;
                        item.person2FirstnameZhs = snapshot2.val().firstnameZhs;
                        item.person2LastnameZhs = snapshot2.val().lastnameZhs;
                    });
                    const k :FirebaseObjectObservable<any> = af.database.object('/relationshipCategory/' + item.category, { preserveSnapshot: true })
                    k.subscribe(snapshot3 => {
                        console.log(snapshot3.key)
                        item.categoryNameEng = snapshot3.val().nameEng;
                        item.categoryNameZhs = snapshot3.val().nameZhs;
                    });

                    const l :FirebaseObjectObservable<any> = af.database.object('/relationship/' + item.relationship, { preserveSnapshot: true })
                    l.subscribe(snapshot4 => {
                        console.log(snapshot4.key)
                        item.relationshipNameEng = snapshot4.val().nameEng;
                        item.relationshipNameZhs = snapshot4.val().nameZhs;
                    });
                }

                return items;
            });
        relationshipP2Ps$.subscribe(relationshipP2Ps => this.relationshipP2Ps=relationshipP2Ps);

now this all works great but when it runs I get the following error:

/src/app/relationship-p2p/relationship-p2p.service.ts:2:15 
    Type 'Observable<any[]>' is not assignable to type 'FirebaseListObservable<any>'.   Property '$ref' is missing in type 'Observable<any[]>'.

any ideas on how to rewrite this resulting in error free?