VideosMy ProjectsProgramming BlogGallery
  1. Home
  2. Blog
  3. Create an Observable using RxJS
Programming Blog

Atom/RSS Feed

typescript/rxjs

Create an Observable using RxJS

typescript/rxjs

Creating an Observable in different ways is sometimes required based on the situation at hand. This is all you need to know!

Create a completed Observable

const someObject: string = 'some text';
return Observable.of(someObject);

Create a non-completed Observable

const someObject: string = 'some text';
return Observable.create((observer: Observer<string>) => {
    observer.next(someObject)
);

Create an eventually completing Observable

return Observable.create((observer: Observer<string>) => {
    observer.next('derp');
    setTimeout(() => {
        observer.next('completed now');
        observer.complete();
    }, 100);
);
Join my mailing list