Search code examples
javascriptrxjsangular2-observablesbehaviorsubject

How to re-emit the last value of a subject


I want to re-emit the last value of a BehaviourSubject to the existing subscriptions. I tried last(), publishlast(), share(), refcount(). But it doesn't trigger the existing subscriptions again with the last emitted value.


Solution

  • If sub is your BehaviorSubject, this would work:

    sub.next(sub.value)