当元素隐藏在Angular2中时,如何在ngFor(异步管道)中使用observable
我有以下html模板:当元素隐藏在Angular2中时,如何在ngFor(异步管道)中使用observable,angular,rxjs,observable,Angular,Rxjs,Observable,我有以下html模板: <div *ngIf="googleSearchVisible"> <div *ngFor="let location of googleSearchLocations | async"> </div> </div> 现在,当我开始将数据推送到可观察的位置时,什么都没有发生。我相信这是因为元素不支持可观察的 我曾尝试添加googleSearchLocations.subscribe在onInit期间,这会强制调
<div *ngIf="googleSearchVisible">
<div *ngFor="let location of googleSearchLocations | async"> </div>
</div>
现在,当我开始将数据推送到可观察的位置时,什么都没有发生。我相信这是因为元素不支持可观察的
我曾尝试添加googleSearchLocations.subscribe
在onInit
期间,这会强制调用服务,甚至使ngIf可见,但ngFor仍然没有呈现任何内容
我如何以这种方式强制执行可观察性
p.S.
googleSearchVisible
在中打开。加载数据时执行。我发现它在隐藏时可以正常工作
<div [hidden]="!googleSearchVisible">
<div *ngFor="let location of googleSearchLocations | async"> </div>
</div>
这并不能解释为什么即使使用subscribe
,也不会呈现任何内容
在上找到相关问题。在角度上似乎存在缺陷。可能的重复不是重复,这是一个单独的问题,关于ngIf下可观测物的行为。它可以用来解决你提到的问题,所以它们在某种程度上是相关的,但在我看来根本不是重复的。