• +91 9723535972
  • info@interviewmaterial.com

RxJS Interview Questions and Answers

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);
    });
  }
}

Comment(S)

Show all Coment

Leave a Comment




NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners