Ragavan Randy
Ragavan Randy

Reputation: 181

What is the purpose of Observable.of operator in RXJS library?

data = [{'info':'success'},{'info':'fail'}];
public getResults(page: Page,data:any[]): Observable<PagedData<CorporateEmployee>> {
    return Observable.of(data).map(data => this.getPagedData(page,data));
}

In the above code what is the purpose of the Observable.of operator?

Upvotes: 4

Views: 1271

Answers (1)

Suren Srapyan
Suren Srapyan

Reputation: 68665

It wraps the array object into the Observable stream for later Observable processing. Your function returns an Observable, the map function is the Observable function (also array has this), and if you want to work with Observable stream, you need to convert your array into the Observable stream and use its functions.

Upvotes: 6

Related Questions