Hello guys,
I'm following the doc here but I got this error Property 'do' does not exist on type 'FirebaseListObservable<any[]>' when trying to run the "Retrieving the snapshot" code. My code is mostly the same with the one in tutorial.
var items = this.af.database.list('/organizations', { preserveSnapshot: true });
items
.do(snapshots => {
snapshots.forEach(snapshot => console.log(snapshot.key()));
})
.subscribe(snapshots => console.log(snapshots.length));
My angularfire2 version is 2.0.0-beta.0. NodeJS version is 4.4.4.
Thank you.
Hey @ngocnb-2nf. What do your imports look like? You may have to import the do operator from rxjs.
Hi @davideast, below is my import:
import { Injectable, Inject } from '@angular/core';
import { FirebaseRef, AngularFire } from 'angularfire2';
I read file utils/firebase_list_factory.ts and see the import below:
import 'rxjs/add/operator/mergeMap'; import 'rxjs/add/operator/map';
There's no operator do here. I tried to add it manually but got not luck :).
@ngocnb-2nf
Can you create a plnkr? This is usually a problem with the import statement.
@ngocnb-2nf
import 'rxjs/add/operator/do';
Adding this at the top solved the issue for me.
Thanks, @UzairNouman!
In my case I have
import 'rxjs/add/operator/do';
get the same error
here is my code
getFamilyType(): Observable<IFamilyType[]> {
return this._http.get<IFamilyType[]>(this._familyTypeUrl)
.do(data => console.log('All: ' + JSON.stringify(data)))
.catch(this.handleError);
}
@TorajKhavari That might be because of the recent changes in RxJS, try the following:
import {tap} from "rxjs/operators"; // I believe tap replaces do now, gotta confirm
Also, now to use those operators, you need to use the pipe() for chaining like:
.pipe(tap(data => console.log('All: ' + JSON.stringify(data))))
This link should give you a good summary of the changes that appeared in RxJS 6:
https://auth0.com/blog/whats-new-in-rxjs-6/
Hope that helps.
Most helpful comment
@ngocnb-2nf
import 'rxjs/add/operator/do';
Adding this at the top solved the issue for me.