2

I am using AngularFire with RxJS 5.4.0 and Firebase. This below code works fine:

 this.questions$ = dbQuestions$.map(snapshots =>
    snapshots.map(data =>
    this.FilterControls(data)
  ));

When I use the code below with RXJS 6.5.1, Angular 8 and Firestore (shown below), I receive the Error:

Property 'map' does not exist on type 'AngularFirestoreCollection<{}>'

 this.questions$ = dbQuestions$.map(snapshots => {
   snapshots.map(data => this.FilterControls(data))
 });
Christopher Peisert
  • 21,862
  • 3
  • 86
  • 117
DEV
  • 949
  • 1
  • 9
  • 29

1 Answers1

0

The error "map does not exist on type AngularFirestoreCollection<{}>" is due to breaking changes made in RXJS version 5.5.

Pipeable Operators

Starting in version 5.5 we have shipped "pipeable operators", which can be accessed in rxjs/operators... These are meant to be a better approach for pulling in just the operators you need than the "patch" operators found in rxjs/add/operator/*.

With the new pipeable operators, your code would look like:

import { Component } from '@angular/core';
import { AngularFirestore, AngularFirestoreCollection } from 'angularfire2/firestore';

import { Observable } from 'rxjs/Observable';
import { map } from 'rxjs/operators';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  dbQuestionCollection: AngularFirestoreCollection<{}>;
  dbQuestions$: Observable<{}[]>;

  constructor(private afs: AngularFirestore) {
    this.dbQuestionCollection = this.afs.collection<{}>('questions');
    this.dbQuestions$ = this.dbQuestions$ = this.dbQuestionCollection.snapshotChanges().pipe(
      map(actions => actions.map(a => {
        const data = a.payload.doc.data(); // DB Questions
        const id = a.payload.doc.id;
        return { id, ...data };
      }))
    )
  }
}
Community
  • 1
  • 1
Christopher Peisert
  • 21,862
  • 3
  • 86
  • 117
  • Above code is not working. Now it says error "pipe does not exist on type AngularFirestoreCollection<{}>" I tried to import import { map,pipe } from 'rxjs/operators'; but the operators doesnt have pipe it seems... – DEV Aug 10 '19 at 12:28
  • i tried with valuechanges and snapshotchanges both still is giving error like below this.questions$ = dbQuestions$.valueChanges().pipe(map(snapshots => { snapshots.pipe(map(data => this.FilterControls(data))) })); Error Message: pipe doesnt exisit on type unknown[] – DEV Aug 10 '19 at 12:46
  • @Dev See updated code example. – Christopher Peisert Aug 10 '19 at 13:04