Get one object from observable array

ⅰ亾dé卋堺 提交于 2019-12-05 16:05:32

You need to be treating the observable value as though it is a stream of arrays, rather than attempting to treat it like a stream of streams of items. The values in your observable are single points of data that each contain their own array.

getTransaction(id: number): Observable<Transaction>{
    return this.getTransactions().pipe(
        map(txs => txs.find(txn => txn.id === id))
    );
}

What you're doing here is mapping each array in your stream into whatever item has an ID that matches the parameter.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!