Ad
"Property 'map' Does Not Exist On Type '{}'" While Trying To Get Collection From Firebase Firestore
I have followed the documentation here to get data with document id from firestore.
import { Injectable } from '@angular/core';
import { AngularFirestore, AngularFirestoreCollection } from '@angular/fire/firestore';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import 'rxjs/add/operator/map';
@Injectable()
export class UserService {
userCol : AngularFirestoreCollection<UserInter>;
users : Observable<UserInter[]>;
constructor(private afs:AngularFirestore) { }
GetUsers(){
this.userCol = this.afs.collection<UserInter>('users');
this.users = this.userCol.snapshotChanges().pipe(
map(changes =>{
error here-> return changes.map(a => {
const data = a.payload.doc.data() as UserInter;
data.id = a.payload.doc.id;
return data;
})
}))
return this.users;
}
export interface UserInter {
email ?: string,
Firstname ?: string,
Lastname ?: string,
Address ?: string,
}
export interface UserInterid extends UserInter {id ?: string }
When I ng-serve my application I get this error
Property 'map' does not exist on type '{}'
Ad
Answer
I fixed that error by using map operator without pipe. This code is working
import { Injectable } from '@angular/core';
import { AngularFireAuth } from 'angularfire2/auth';
import { AngularFirestore, AngularFirestoreCollection } from '@angular/fire/firestore';
import { Observable } from 'rxjs';
import 'rxjs/add/operator/map';
@Injectable()
export class UserService {
uid;
userCol : AngularFirestoreCollection<UserInter>;
users : Observable<any>;
constructor(private Uauth:AngularFireAuth, private afs:AngularFirestore) { }
GetUsers(){
this.userCol = this.afs.collection('users');
this.users = this.userCol.snapshotChanges()
.map(action => {
return action.map(a => {
const data = a.payload.doc.data() as UserInter;
const id = a.payload.doc.id;
return {id, data };
})
})
return this.users;
}
}
export interface UserInter {
email ?: string,
pass ?: string,
Rpass ?: string,
Firstname ?: string,
Lastname ?: string,
Society ?: string,
Landmark ?: string,
Address ?: string,
PrimaryNo ?: string,
SecondaryNo ?: string,
ExpiryDate ?: Date,
Orders ?: string,
}
export interface UserInterid extends UserInter {id ?: string }
Ad
source: stackoverflow.com
Related Questions
- → Make a Laravel collection into angular array (octobercms)
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → Angularjs not working inside laravel form
- → Analysis of Flux implementations
- → how to write react component to construct HTML DOM
- → angular ng-repeat and images in a row
- → Conditional BG Color on AngularJS
- → Should I 'use strict' for every single javascript function I write?
- → getting the correct record in Angular with a json feed and passed data
- → "Undefined is not a function" at .toBe fucntion
- → angularjs data binding issue
- → Angular / JavaScript auto hydrate an instance
- → Convert generic text string in json object into valid url using Angular
Ad