Why in this situation next function doesn't send information?

Viewed 32

I'm learning Subject from RXJS and I don’t understand why in this situation the next() function doesn’t send the information:

import {Subject, from} from 'rxjs';

const subject = new Subject<any>();

subject.subscribe({
    next: (v) => console.log(`observerA: ${v}`),
});
subject.subscribe({
    next: (v) => console.log(`observerB: ${v}`),
});

const observable = from([1, 2, 3]);
observable.subscribe(subject);

subject.next(4) // not working
1 Answers

If you update with complete then you will see that it automatically completed when you pass directly subject to subscribe.

subject.subscribe({
    next: (v) => console.log(`observerA: ${v}`),
    error: (error) => console.log(error),
    complete: () => console.log('completed') 
});
Related