数据未显示。 Ng-off-for-off:null?

问题描述 投票:0回答:1

嗨,我想绑定来自firebase的数据。而且我没有收到错误,但数据没有显示。在检查元素我得到

<!--bindings={
  "ng-reflect-ng-for-of": null
}-->

我的app.component.html是

<ul>
    <li *ngFor="let item of items | async">
        {{item.title}}
    </li>
</ul>

我的app.component.ts是

import { Component } from "@angular/core";
import { AngularFirestore } from "angularfire2/firestore";
import { Observable } from "rxjs/Observable";
import { AngularFire, FirebaseListObservable } from "angularfire2";


@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.css"]
})
export class AppComponent {
  title = "app";

  constructor(db: AngularFirestore) {}
}

如果需要app.module.ts我可以添加它。所以问题是如何摆脱那种反射的东西并显示我的数据。谢谢

angular angularfire angularfire2
1个回答
0
投票

ng-reflect-ng-for-of评论是Angular的约束性信息。即使在生产中,这些评论仍然存在,尽管它们可能在那里是空的。

你在帖子中排除app.component.ts的代码吗?

您的问题可能是由于未在组件中设置items属性引起的。既然你正在使用async管道,那么你暗示你期望items是一个可观察的。尝试按如下方式设置items属性:

@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
    styleUrls: ["./app.component.css"]
})
export class AppComponent {
    title = "app";
    items: Observable<{title: string}>;

    constructor(db: AngularFirestore) {
        this.items = db.collection<{title: string}>('items').valueChanges();
    }
}

更多信息可以在Angular Firestore documentation找到。

© www.soinside.com 2019 - 2024. All rights reserved.