Firestore从angular获取单个数据

Firestore从angular获取单个数据,angular,typescript,google-cloud-firestore,ionic4,Angular,Typescript,Google Cloud Firestore,Ionic4,我是新来的。请帮助我从firestore获取单个数据。我从数据库中获取完整数据,但我需要从数据库中获取特定数据。 这是我的angular代码,用于获取完整数据。我提到了两个代码文件,第一个是服务,另一个是显示代码 服务台 import { Injectable } from '@angular/core'; import { AngularFirestore,AngularFirestoreDocument,AngularFirestoreCollection } from '@angular/

我是新来的。请帮助我从firestore获取单个数据。我从数据库中获取完整数据,但我需要从数据库中获取特定数据。 这是我的angular代码,用于获取完整数据。我提到了两个代码文件,第一个是服务,另一个是显示代码

服务台

import { Injectable } from '@angular/core';
import { AngularFirestore,AngularFirestoreDocument,AngularFirestoreCollection } from '@angular/fire/firestore';
import { User } from '../models/user';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

@Injectable({
  providedIn: 'root'
})
export class RegisterService {
  private registerCollection : AngularFirestoreCollection<User>;
  private  resgisters : Observable<User[]>;
  private registerDocu : AngularFirestoreDocument<User>;

  constructor(public db : AngularFirestore) {
    this.registerCollection = db.collection<User>('Register');
    this.resgisters = db.collection('Register').valueChanges();

    this.resgisters = this.registerCollection.snapshotChanges().pipe(
      map(actions => {
        return actions.map(a => {
          const data = a.payload.doc.data();
          const id = a.payload.doc.id;
          return { id, ...data };
        });
      })
    );
    }
    addRegister(user: User) {
       this.registerCollection.add(user);
    }
    getRegister(){
      return this.resgisters;
    }

}

为了从Firestore数据库中获取单个对象,您需要查询文档。根据您的代码结构,getRegister()方法应为:

getRegister(node) {
   return this.db.Doc<User>('Register/' + node).valueChanges();
}
getRegister(节点){
返回此.db.Doc('Register/'+node).valueChanges();
}
您可以在library github页面上找到文档:

您试图获取的“特定”数据是什么?您可以使用查询。它会过滤你的数据。
getRegister(node) {
   return this.db.Doc<User>('Register/' + node).valueChanges();
}