【发布时间】:2019-11-25 05:45:23
【问题描述】:
我正在尝试使用async 管道来实现ngIf。但不起作用。有人帮我吗?
这是我的html:
<div class="response-container">
xx {{response | async | json }}
<div class="failed-error" *ngIf="(response.responseFail | async )">
{{response.message}}
</div>
<div class="success-msg" *ngIf="(response.responseSucc | async) === 'true' ">
{{response.message}}
</div>
</div>
在上面的xx {{response | async | json }} 中打印为:
xx { "responseFail": false, "responseSucc": true, "message": "success" }
但为什么这不适用于*ngIf 条件?
【问题讨论】:
-
控制台中是否显示任何错误?
-
您需要将绑定值绑定到异步,因此在评估该值时它将返回真或假,例如。
response | async as _response但我会将其添加到响应容器中,然后在您的失败错误中我会像这样检查*ngIf="_response.responseFail而不是您 asnyc。 -
@JohnKane 是的,没有错误。
标签: angular angular-directive angular8