嗨,我想绑定来自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我可以添加它。所以问题是如何摆脱那种反射的东西并显示我的数据。谢谢
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找到。