Question - How can we get current value of RxJS Subject or Observable?
Answer -
The observable and subjects does not have a current value, and is emitted or passed to the subcribers and yhe observable is done with it.If we want to have the current or uses BehaviorSubject that is designed for this purpose.As it keeps the emitted value and emits to new subscribers.
import {Storage} from './storage';
import {Injectable} from 'angular2/core';
import {Subject} from 'rxjs/Subject';
@Injectable()
export class SessionStorage extends Storage {
private _isLoggedInSource = new Subject();
isLoggedIn = this._isLoggedInSource.asObservable();
constructor() {
super('session');
}
setIsLoggedIn(value: boolean) {
this.setItem('_isLoggedIn', value, () => {
this._isLoggedInSource.next(value);
});
}
}