"Property 'map' does not exist on type '{}'" 尝试从 firebase firestore 获取集合时
"Property 'map' does not exist on type '{}'" while trying to get collection from firebase firestore
我已按照文档 here 从 firestore 获取具有文档 ID 的数据。
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 }
当我 ng-serve 我的应用程序时,我收到此错误
Property 'map' does not exist on type '{}'
GetUsers(){
this.userCol = this.afs.collection<UserInter>('users');
this.users = this.userCol.stateChanges(['added']).pipe(
map(changes =>{
return changes.map(a => {
const data = a.payload.doc.data() as UserInter;
data.id = a.payload.doc.id;
return data;
})
}))
return this.users;
}
你能试试这个吗
this.afs.collection<UserInter>('users').stateChanges(['added']).pipe(map(changes => {
return changes.map(a => {
const data = a.payload.doc.data() as UserInter;
const id = a.payload.doc.id
return { id, ...data }
})
}))
我通过使用不带管道的地图运算符修复了该错误。
此代码有效
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 }
我已按照文档 here 从 firestore 获取具有文档 ID 的数据。
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 }
当我 ng-serve 我的应用程序时,我收到此错误
Property 'map' does not exist on type '{}'
GetUsers(){
this.userCol = this.afs.collection<UserInter>('users');
this.users = this.userCol.stateChanges(['added']).pipe(
map(changes =>{
return changes.map(a => {
const data = a.payload.doc.data() as UserInter;
data.id = a.payload.doc.id;
return data;
})
}))
return this.users;
}
你能试试这个吗
this.afs.collection<UserInter>('users').stateChanges(['added']).pipe(map(changes => {
return changes.map(a => {
const data = a.payload.doc.data() as UserInter;
const id = a.payload.doc.id
return { id, ...data }
})
}))
我通过使用不带管道的地图运算符修复了该错误。 此代码有效
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 }