Last active
April 26, 2017 04:54
-
-
Save Ibro/cac0657e3bb5f1330957bbea15ff86a0 to your computer and use it in GitHub Desktop.
Creating Observable error - error method on observer - Coding Blast - www.codingblast.com
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
import {Observable} from 'rxjs'; | |
let words = ['coding blast', 'badword', 'coding', 'blast']; | |
let source = Observable.create(observer => { | |
for (let word of words) { | |
if (word === 'badword') { | |
observer.error('Bad word!'); | |
} | |
observer.next(word); | |
} | |
observer.complete(); | |
}); | |
let subscriber = { | |
next(value) { | |
console.log('Subscriber - next: ', value); | |
}, | |
error(err) { | |
console.log('Subscriber - error: ', err); | |
}, | |
complete() { | |
console.log('Subscriber - complete'); | |
} | |
}; | |
console.log('before subscribe'); | |
source.subscribe(subscriber); | |
console.log('after subscribe'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment