const mySubject = new Subject(); const myObservable = mySubject.asObservable(); myObservable.subscribe(val => console.log(val)); mySubject.next("Hello World!");
const mySubject = new Subject(); mySubject.next("Hello World!"); const myObservable = mySubject.asObservable(); myObservable.subscribe(val => console.log(val));This code creates a new Subject called `mySubject`, emits the value "Hello World!" using the `next()` method on the Subject, and then converts the Subject into an Observable called `myObservable` using the `asObservable()` method. It then subscribes to the Observable and logs out the value that it receives. Package library: RxJS.