简体   繁体   English

Ionic Angular Firestore 不在视图中显示单个文档数据

[英]Ionic Angular Firestore not displaying single document data in view

I am trying to retrieve a single document in a collection and display it in a view, but it always results in a blank page.我试图检索集合中的单个文档并将其显示在视图中,但它总是导致空白页。

I have a service and a component.我有一个服务和一个组件。

Here is my service:这是我的服务:

getReview(reviewID) {
      console.log('review id sent to service: ' + reviewID);
      this.reviewDoc = this.af.doc(`reviews/${reviewID}`);
      return this.reviewDoc.valueChanges();
  }

Here is my component:这是我的组件:

    ngOnInit() {
    const reviewID = this.route.snapshot.params.id;
    this.getReview(reviewID);
    }

    getReview(reviewID) {
    this.reviewDetailsService.getReview(reviewID).subscribe((data) => {
      this.review = data;
      console.log(this.review);
    });
    }

The console log shows this: {imgURL: "http://someimage.jpg",caption: "This is my caption}控制台日志显示: {imgURL: "http://someimage.jpg",caption: "This is my caption}

In my HTML view I am doing this:在我的 HTML 视图中,我这样做:

    <ion-content class="ion-padding">
    <div *ngFor="let rev of review">
        {{rev.caption}}
    </div>
    </ion-content>

This does not display anything on the page.这不会在页面上显示任何内容。

Am I missing something?我错过了什么吗?

You cannot use ngFor over an object, ngFor used over a collection, change your view as您不能在对象上使用 ngFor,在集合上使用 ngFor,请将您的视图更改为

 <div>
    <h1> {{review.caption}} </h1>
 </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM