首页 > 解决方案 > 跨父母查询不返回任何数据

问题描述

我正在对 firebase-firestore 进行查询,但它没有返回我的代码的任何数据。这里是所有类别的打印位置以及您获得每个类别 ID 的位置:

<div class="categorias" >
        <a mat-list-item>Categorias</a>
        <a mat-list-item *ngFor="let categoria of categorias | async" routerLink="categorias/{{categoria.id}}">
          <mat-icon>category</mat-icon>
          <span class="sidenav-caption">{{categoria.nome}}</span>
        </a>
      </div>

这是我的查询,没有错误,但没有数据:

produtos: Observable<Produtos[]>;
  produtosCollection: AngularFirestoreCollection<Produtos>;
  constructor(
    private router: Router,
    private route: ActivatedRoute,
    private produtoService: ProdutosService,
    private afs: AngularFirestore
    ) { }

ngOnInit() {
        const categoria = this.route.snapshot.paramMap.get('id');
        this.produtosCollection = this.afs.collection('produtos', ref => {
          return ref.where('categoria', '==', categoria);
        });
        this.produtos = this.produtosCollection.valueChanges();
      }

只有标签 h1 的内容正在准备中,其余的都没有:

<h1>Test </h1>
<div *ngFor="let produto of produtos | async">
    <p>{{produto.descricao}}</p>
</div>

分类

为产品

在此处输入图像描述

标签: javascriptangulargoogle-cloud-firestoreangularfire2

解决方案


推荐阅读