import { Subject } from 'rxjs'; const subject = new Subject(); // Subscribe to the subject subject.subscribe({ next: value => console.log(value), error: error => console.error(error), complete: () => console.log('Complete') }); // Emit values to the subject subject.next('Hello'); subject.next('world'); subject.complete();
import { Subject } from 'rxjs'; const subject = new Subject(); // Subscribe to the subject twice subject.subscribe(value => console.log(`Subscription 1: ${value}`)); subject.subscribe(value => console.log(`Subscription 2: ${value}`)); // Emit a value to the subject subject.next('Hello');This example creates a new Subject and subscribes to it twice. It then emits a value to the subject and the value is received by both subscribers. The package library for rxjs is "@rxjs".