【发布时间】:2017-11-19 17:34:00
【问题描述】:
我正在尝试从 firebase 获取并显示单个值。
我当前的 .ts 文件如下所示:
storestat$: Observable<any[]>;
constructor(afDb: AngularFireDatabase) {
this.storestat$ = afDb.list<any>('MyShop').snapshotChanges();
}
我想使用 {{}} 绑定在 html 中显示 storeStatus 值。类似于以下内容:
<button>{{ storeStatus }} Status</button>
我最初尝试使用以下内容:
<ng-container *ngFor="let s of storestat$ | async">...
<button>{{ s.storeStatus }}</button>
但这当然行不通。
我尝试搜索答案,但它们似乎不太相关,因为它们都指向从列表中获取多个特定值。
我正在使用 angularfire2 和 angular5。
我是 angular5 的新手,因此我们将不胜感激,包括任何教育指针。
【问题讨论】:
-
调试尝试
<p>{{ s | json }}</p>并检查数据是否到来? -
我收到以下错误:AppComponent.html:4 ERROR TypeError: Converting circular structure to JSON at JSON.stringify (
) at JsonPipe.transform (common.js:5954) at Object. eval [as updateDirectives] (AppComponent.html:4) at Object.debugUpdateDirectives [as updateDirectives] (core.js:14339) at checkAndUpdateView (core.js:13508) at callViewAction (core.js:13858) at execComponentViewsAction (core. js:13790)... -
试试
.valueChanges()方法。 -
这也给出了同样的错误。我在下面发布了一个解决方案,但我认为它有点混乱。
标签: angular firebase firebase-realtime-database angularfire2 angular5