Reputation: 4289
If I do this in browser console, the constructor function doesnot seems to be called-
Observable.create(observer =>
console.log('this is the observer'); //doesn't gets logged
this.alertObserver = observer
);
or this :-
new Observable(observer =>
console.log('this is the observer'); //doesn't gets logged
this.alertObserver = observer
);
I have tried importing Observer through
import {Observable} from 'rxjs/Observable';
and
import {Observable} from 'rxjs/Rx';
but with no help.
Any suggestion ?
Upvotes: 3
Views: 2631
Reputation: 11
Not this:
import {Observable} from 'rxjs/Rx';
This: import {Observable} from 'rxjs';
Upvotes: 1
Reputation: 52847
Rx observables are lazy loaded. You need at least one subscriber.
Try:
var observable = Observable.create(observer =>
console.log('this is the observer');
this.alertObserver = observer
);
observable.subscribe();
Upvotes: 7