简体   繁体   中英

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.

Would like to improve previous ans.. async pipe itself check for null or undefined value therefore no need to check .length>0 . So improved answer would be

*ngIf="(post | async)"

or another way is

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

Hope this will help you :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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