gpt4 book ai didi

AngularFirestore : Property 'id' does not exist on type 'QueryDocumentSnapshot'

转载 作者:行者123 更新时间:2023-12-03 16:52:05 25 4
gpt4 key购买 nike

这是 Angular5 和 Firestore 的问题

我想做的事

  • 获取一个 Firestore 集合,它在我的数据库中被称为 minutes
  • 设置我的组件变量,也称为 minutes , 等于一个包含每个 minute 的 Observable 对象文档 ID。

  • 现在我收到这个错误
    Property 'id' does not exist on type 'QueryDocumentSnapshot<any>'
    这是我从 Firestore 收集收藏的地方
    minutesArray: AngularFirestoreCollection<any>;
    minutes: Observable<any[]>;

    constructor(private afs: AngularFirestore) {
    this.minutesArray = afs.collection<any>('minutes', ref => ref.orderBy('year', 'desc'));
    this.minutes = this.minutesArray
    .snapshotChanges()
    .pipe(map(actions => actions.map(a => {
    const data = a.payload.doc.data();
    #### NEXT LINE ERRORS OUT ####
    const id = a.payload.doc.id;
    return { id, ...data };
    }))
    );

    为什么会抛出这个错误?

    Github Issue没有提供答案。

    `

    最佳答案

    尝试使用:

    doc.payload.doc['id']
    代替:
    doc.payload.doc.id

    关于AngularFirestore : Property 'id' does not exist on type 'QueryDocumentSnapshot<any>' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50953658/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com