javascript - How to re-emit the last value of a subject - Stack Overflow

I want to re-emit the last value of a BehaviourSubject to the existing subscriptions. I tried last(), p

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.

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.

Share Improve this question edited Mar 5, 2018 at 8:12 jonrsharpe 122k30 gold badges268 silver badges476 bronze badges asked Mar 4, 2018 at 22:24 codermancoderman 1,5143 gold badges23 silver badges35 bronze badges 3
  • this.subject.take(1).subscribe(item => this.subject.next(item))? But why do you need to do this; what's the context? – jonrsharpe Commented Mar 4, 2018 at 22:27
  • This looks like it is setting up the subscriber. I want the subject to re-emit the last value. – coderman Commented Mar 4, 2018 at 22:46
  • It does, and that is what it does. It will take one value, a replay of the last value, and push it back into the subject to get re-emitted. – jonrsharpe Commented Mar 5, 2018 at 8:11
Add a ment  | 

1 Answer 1

Reset to default 5

If sub is your BehaviorSubject, this would work:

sub.next(sub.value)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745392669a4625734.html

相关推荐

  • javascript - How to re-emit the last value of a subject - Stack Overflow

    I want to re-emit the last value of a BehaviourSubject to the existing subscriptions. I tried last(), p

    22小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信