Skip to content

Instantly share code, notes, and snippets.

@Ibro
Last active April 26, 2017 04:54
Show Gist options
  • Save Ibro/28dc9c328f9f356815c795cdc11ce518 to your computer and use it in GitHub Desktop.
Save Ibro/28dc9c328f9f356815c795cdc11ce518 to your computer and use it in GitHub Desktop.
Creating observable error - Coding Blast - www.codingblast.com
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