I understand that an Observable
is a dynamic object, that changes over time. I am however, looking to create a function, that will return just a single snapshot of that observable.
I have the following function, that uses AngularFire2
and returns an Observable
.
import { Observable } from 'rxjs/Observable';
findMessages(chatItem: any): Observable<any[]> {
return this.af.database.list('/message/', {
query: {
orderByChild: 'negativtimestamp'
}
}).map(items => {
const filtered = items.filter(
item => ((item.memberId1 === chatItem.memberId1 && item.memberId2 === chatItem.memberId2)
|| (item.memberId1 === chatItem.memberId2 && item.memberId2 === chatItem.memberId1))
);
return filtered;
});
}
This works perfectly, and if I display this list, it dynamically updates as items are added or removed.
Question
How do I call this function, and convert the Observable
to a static array of items?
I have looked here and tried to retrofit their example to my situation, but cannot seem to do so.
Any help appreciated.