Created
November 15, 2018 16:23
-
-
Save nlharri/5ca078b44001e4743c4024e4feedce3a to your computer and use it in GitHub Desktop.
RxJS Tutorial - Hello World! - Observable subscribe with object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Observable } = require('rxjs'); | |
// Create an Observable | |
var observable = Observable.create((observer) => { | |
observer.next('Hello World!'); | |
observer.next('Hello Again!'); | |
observer.complete(); | |
observer.next('Bye'); // this will not be shown | |
}); | |
// Subscribe to the Observable, and print stream to the console | |
observable.subscribe({ | |
next: function(x) { console.log('next: ' + x) }, | |
error: function(error) { console.log('error: ' + error) }, | |
complete: function() { console.log('completed') } | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment