【问题标题】:How to use observable in ngFor (async pipe) when the element is hidden in Angular2当元素隐藏在Angular2中时如何在ngFor(异步管道)中使用observable
【发布时间】: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 中打开。

【问题讨论】:

标签: angular rxjs observable


【解决方案1】:

我发现hidden 确实可以正常工作

<div [hidden]="!googleSearchVisible">
    <div *ngFor="let location of googleSearchLocations | async"> </div>
</div>

这并不能解释为什么即使使用subscribe 也不会呈现任何内容。

github 上发现了一个相关问题。角度好像有bug。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-25
    • 2016-02-18
    • 1970-01-01
    • 1970-01-01
    • 2018-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多