【发布时间】:2016-10-26 11:06:10
【问题描述】:
我有以下 html 模板:
<div *ngIf="googleSearchVisible">
<div *ngFor="let location of googleSearchLocations | async"> </div>
</div>
现在,当我开始将数据推送到 observable 时,什么都没有发生。我确实相信会发生这种情况,因为该元素不订阅 observable。
我尝试在onInit 期间添加googleSearchLocations.subscribe,这确实会强制调用服务,甚至使 ngIf 可见,但 ngFor 仍然没有呈现任何内容。
我怎样才能以这种方式强制执行 observable?
附:当我加载数据时,googleSearchVisible 在.do 中打开。
【问题讨论】:
-
这不是重复的,它本身是一个单独的问题,关于可观察对象在 ngIf 下的行为。它可以用来解决您提到的问题中的问题,因此它们在某种程度上是相关的,但在我看来根本不是重复的。
标签: angular rxjs observable