数据不显示.Ng-reflect-ng-for-off:null? [英] Data is not showing. Ng-reflect-ng-for-off:null?

查看:20
本文介绍了数据不显示.Ng-reflect-ng-for-off:null?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 firebase 绑定数据.而且我没有收到错误,但没有显示数据.在检查元素中我得到

Hi i am trying to bind a data from firebase. And I'm not getting errors but data is not showing. In inspect element i'm getting

<!--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 的东西并显示我的数据.谢谢

if app.module.ts is needed i can add it. So the thing is how to get rid of that ng-reflect thing and show my data. Thank you

推荐答案

ng-reflect-ng-for-of 注释是 Angular 的绑定信息.即使在生产中,这些评论仍然存在,尽管它们在那里可能是空的.

The ng-reflect-ng-for-of comment is binding information for Angular. Those comments will still exist, even in production, though they may be empty there.

您是否在帖子中从 app.component.ts 中排除了代码?

Are you excluding code from your app.component.ts in your post?

您的问题可能是由于您的组件中未设置 items 属性引起的.由于您使用的是 async 管道,因此您暗示您希望 items 成为可观察对象.尝试如下设置您的 items 属性:

Your issue is probably caused by the items property not being set in your component. Since you're using the async pipe, you are implying that you are expecting items to be an observable. Try setting your items property as follows:

@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();
    }
}

更多信息可以在

More information can be found in the Angular Firestore documentation.

这篇关于数据不显示.Ng-reflect-ng-for-off:null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆