简体   繁体   English

Firestore在ngIf条件中剥离异步数据

[英]Firestore stripping async data inside ngIf conditionals

My app is running Angular 4.4.5 and I'm using firebase via angularfire2 ^5.0.0-rc.3. 我的应用程序正在运行Angular 4.4.5,并且正在通过angularfire2 ^ 5.0.0-rc.3。使用firebase。

My main branch is running off the Firebase Realtime DB, and everything works fine, but as I'm moving to the FireStore DB, I'm having a problem now where ngIf statements don't let my Observables through... 我的主分支正在Firebase Realtime DB上运行,并且一切正常,但是当我移至FireStore DB时,现在遇到了一个问题,即ngIf语句不允许我的Observables通过...

So basically I have an to trigger a loader while content is loading, but the data always comes back null inside those conditionals... 所以基本上我有一个在内容加载时触发加载器,但是在这些条件中数据总是返回null……

The conditional seems to be coming back true, because plain text will show up inside of it, but the data itself comes back null... 该条件似乎恢复为真,因为纯文本将显示在其中,但是数据本身返回为null。

 {{(analyses$ | async) | json}} <!-- This works like a charm --> <div *ngIf="(analyses$ | async)"> {{(analyses$ | async) | json}} <!-- This doesn't work --> HI WORLD <!-- This prints out fine! --> </div> 

What am I missing? 我想念什么?

This is a late response to the original question, but I was experiencing the same issue and dealt with it like so: 这是对原始问题的较晚答复,但是我遇到了相同的问题并按以下方式处理:

<app-dumb-component
  *ngIf="(data$ | async) as data"
  [data]="data"></app-dumb-component>

The key is in the (data$ | async) as data and then using that reference wherever you would be handling the observable within the control. 关键是在(data$ | async) as data ,然后在要处理控件中可观察对象的任何地方使用该引用。

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

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