igorman007
igorman007

Reputation: 89

'of' with 'publishReplay' does not emit value

Example:

const data$ = of(777).pipe(
   publishReplay(1)
);

data$.subscribe(x => console.log(x));

Expected printing "777" to console. Actual: console is empty:(

Upvotes: 0

Views: 46

Answers (1)

NickL
NickL

Reputation: 1960

You're missing data$.connect(); after your subscription.

Alternatively you can use the refCount operator after publishReplay to do this for you automatically.

Upvotes: 2

Related Questions