Skip to content

Angular 5 - firestore Snapshotchanges "supplied parameters do not match any signature of call target" #1473

@SGissubel

Description

@SGissubel

I have been at this for days... Even was following a course on Udemy to help me get started, and a recent one, Plus all the doc's I looked at, it APPEARS as if I am doing everything correctly...

Below, there is a line where I am getting the snapshotchanges of a collect/doc/collection that I have. I have stored in it. And the line below that (commented out) returns fine, and I can get the valuechanges, but I need the doc.id so that I can update/set new values.

But every-way that I try to organize this, it continues to tell me one of a few things, Mostly: "supplied parameters do not match any signature of call target" (from the snapshot shown below), or references missing parameters such as (["add" | "remove"...]). etc. Either I am definitely way off with something... or Something is wrong.

I even tried the version from the Documents, so no need to post those below. I was getting the same errors...

import { Injectable } from '@angular/core';
import { Response } from '@angular/http';
import { AngularFirestore } from 'angularfire2/firestore';
import { map } from 'rxjs/operators';
import { Subject } from 'rxjs/Subject';
import { Observable } from 'rxjs/Observable';
import { Router } from '@angular/router';

import { ISnippet } from '../models/snippets.model';
import { AuthService } from '../../login/auth.service';

@Injectable()
export class SnippetsService {
  snippetsAdded = new Subject<ISnippet[]>();
  snippetsExist = new Subject<boolean>();
  snipObserve: Observable<any[]>;
  userID: string;

  constructor(private db: AngularFirestore,
              private router: Router,
              private authService: AuthService) {
    this.userID = this.authService.getUserID();
  }

  fetchAvailableSnippets() {
  }

  createdNewSnippet(snippet: ISnippet) {
    this.storeNewSnippet(snippet);
  }

  fetchCreatedSnippets() {
  const thing = this.db
      .collection('snippets')
      .doc(this.userID)
      .collection<any>('user-snippets');

     // this.snipObserve = thing.snapshotChanges()
     //  .map(result => {
     //    return result.map(doc => {
     //      const data = doc.payload.doc.data as ISnippet;
     //      const id = doc.paylod.doc.id;
     //      return { id, ...data}
     //    })
     //    }
     //  });

this.snipObserve = thing.snapshotChanges()
  .map(results => {
    return results.map((i) => {
      return {
        id = doc.paylod.doc.id,
        ...doc.paylod.doc.data()
      };
    });
   })
  .subscribe(result => {
     for (const res of result) {
       console.log(res.payload.doc.data());
     }
  });

    // this.db
    //   .collection('snippets')
    //   .doc(this.userID)
    //   .collection('user-snippets')
    //   .valueChanges()
    //   .subscribe((snippets: ISnippet[]) => {
    //     this.snippetsAdded.next(snippets);
    //     if (snippets.length) this.snippetsExist.next(true);
    //   });
  }

  updateSnippet(snippet: ISnippet) {
    const selectedSnip = snippet.id;
    this.db.doc<any>(`snippets/${this.userID}/user-snippets/${selectedSnip}`)
      .update(snippet);
  }

  private storeNewSnippet(snippet: ISnippet) {
    const itemId = this.db.createId();
    const createdAt = firebase.firestore.FieldValue.serverTimestamp();
    const item = { ...snippet, id: itemId, created_at: createdAt};
    this.db.collection('snippets').doc(this.userID).collection('user-snippets').add(item);
    if (!snippet.private) this.storePublicSnippet(snippet);
    else this.router.navigate(['dashboard']);
  }

  private storePublicSnippet(snippet: ISnippet) {
    this.db.collection('snippets').doc('public_snippets').collection('snippets').add(snippet);
    this.router.navigate(['dashboard']);
  }

}


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