Last active
April 26, 2017 04:54
-
-
Save Ibro/28dc9c328f9f356815c795cdc11ce518 to your computer and use it in GitHub Desktop.
Creating observable error - 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: any) { | |
console.log('Subscriber - next: ', value); | |
}, | |
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