简体   繁体   English

如何将可观察的转换为数组? 角4

[英]how to convert observable to array ? angular4

post has a type observable not array , I need a help 帖子具有可观察的类型而不是数组,我需要帮助

在此处输入图片说明

Use the async pipe 使用异步管道

<div *ngIf="(posts | async).length > 0"></div>

to get the values for the current emit of your Observable. 获取您的Observable当前发射的值。

Would like to improve previous ans.. async pipe itself check for null or undefined value therefore no need to check .length>0 . 想改善以前的ans ..异步管道本身检查null或未定义值,因此无需检查.length> 0。 So improved answer would be 所以改进的答案将是

*ngIf="(post | async)"

or another way is 或另一种方式是

*ngIf="post.value.length>0"

Hope this will help you :) 希望这个能对您有所帮助 :)

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

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