2

I have service which first goes to get some status and does

this.changedSource.next(value) changedSource is 'rxjs/Subject'

second service which subscribes to it this.firstService.changed$.subscribe((value) => this.value = value)

second service comes in picture later at the stage so I think it misses the first change. How to resolve this?

The.Bear
  • 5,621
  • 2
  • 27
  • 33
Sumant
  • 276
  • 1
  • 12

1 Answers1

3

If the second service is not subscribed to the observable from the first service at the time it fires, Subject is the wrong choice. If you change it to BehaviorSubject, it will replay the current value to all subscribers who join after the observable fired.

Tyler Jennings
  • 8,761
  • 2
  • 44
  • 39
  • Thanks a lot. Worked. this also helped http://stackoverflow.com/questions/39494058/angular-2-behavior-subject-vs-observable – Sumant Mar 28 '17 at 00:26