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 ?
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();
Not this:
import {Observable} from 'rxjs/Rx';
This: import {Observable} from 'rxjs';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With