Angular 5 - firestore Snapshotchanges "supplied parameters do not match any signature of call target"
See original GitHub issueI 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']);
}
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:11 (3 by maintainers)
@SGissubel Solution: fetchAvailableExercises() { this.fbSubs.push(this.db .collection(‘availableExercises’) .snapshotChanges().pipe( map(docArray => { return docArray.map(doc => { const data = doc.payload.doc.data() as Exercise; const id = doc.payload.doc.id; return { id, …data }; }); }))
I’m not really sure I understand the context here - without matching my nomenclature.
Plus that does’t 100% apply when you have to go inside of collection, then doc, then collection, etc.
But my last one was how I solved it already.
And I was not using pipes when I created this. Though it’s a good note to go back in and update some code!
Cheers!