Solution - Unicast

Subject

Solution

import { Observable } from 'rxjs';

const observable: Observable<number> = new Observable((observer) => {
  console.log('%cNew subscription created', 'background: #222; color: #bada55');
});

observable.subscribe();
observable.subscribe();

Let review the solution code above:

  • First, we import the Observable class from the rxjs module.
  • We create a new instance of the Observable class providing the subscriber function, which receives the Observer.
  • For this example, we simply log out that a new subscription has been created.
  • We then subscribe to the Observable multiple times.
  • Note that we should see two logs in our console, one for each subscriber.

Solution - Unicast

Subject

Solution

import { Observable } from 'rxjs';

const observable: Observable<number> = new Observable((observer) => {
  console.log('%cNew subscription created', 'background: #222; color: #bada55');
});

observable.subscribe();
observable.subscribe();

Let review the solution code above:

  • First, we import the Observable class from the rxjs module.
  • We create a new instance of the Observable class providing the subscriber function, which receives the Observer.
  • For this example, we simply log out that a new subscription has been created.
  • We then subscribe to the Observable multiple times.
  • Note that we should see two logs in our console, one for each subscriber.

Copyright

Site © by LiveLoveApp, LLC

We Can Help!

Need help with RxJS in your project?

Hire Us