angular - foo.subscribe with bar not always working - Stack Overflow

Imagine we have foo$ and bar$ and both of them are BehaviorSubjects.I have a bug in angular that somet

Imagine we have foo$ and bar$ and both of them are BehaviorSubjects.

I have a bug in angular that sometimes in some cases foo$.subscribe(bar$) works fine, in most casses actually.

But sometimes I have a bug and its not working until I do foo$.subscribe(foo => bar$.next(foo)), and even worse it seems like it works the first time and then the second time it dose not work.

I experienced this bug sometimes but still rearly. Not sure even how to make a proper minimal reproduction. I would like to understand what makes this causing the bug? And is the angular team aware of it? I didn't see anywhere so far anyone posting about it.


Have checked if it solves anything by removing zonejs and it dose not.

Imagine we have foo$ and bar$ and both of them are BehaviorSubjects.

I have a bug in angular that sometimes in some cases foo$.subscribe(bar$) works fine, in most casses actually.

But sometimes I have a bug and its not working until I do foo$.subscribe(foo => bar$.next(foo)), and even worse it seems like it works the first time and then the second time it dose not work.

I experienced this bug sometimes but still rearly. Not sure even how to make a proper minimal reproduction. I would like to understand what makes this causing the bug? And is the angular team aware of it? I didn't see anywhere so far anyone posting about it.


Have checked if it solves anything by removing zonejs and it dose not.

Share Improve this question asked Mar 20 at 12:34 Muhamed KarajicMuhamed Karajic 811 silver badge7 bronze badges 4
  • 3 Hi, without a repro this is very hard to investigate. – Matthieu Riegler Commented Mar 20 at 12:37
  • I tougth maybe its a very very general issue which I'm just not aware of. I'll try to make a repo. – Muhamed Karajic Commented Mar 20 at 12:38
  • @MatthieuRiegler here is a minimal repo stackblitz/edit/… You can see in the console hello... is logged once when doing it the first way, and doing it the second way its logged as many times as you click the button. – Muhamed Karajic Commented Mar 20 at 13:10
  • After looking it however myself I see the issue is actully in the this.onDestroy$.next(); call. but still strange that it works fine when changing the line of code. – Muhamed Karajic Commented Mar 20 at 13:12
Add a comment  | 

1 Answer 1

Reset to default 2

When you do this.foo$.pipe(takeUntil(this.onDestroy$)).subscribe(this.bar$);

The bar$ subject actually completes when the foo$ subscription completes (because if the takeUntil).

This is become subscribe(this.bar$) implies

foo$.subscribe({
  next: value => bar$.next(value),
  error: error => bar$.error(error),
  complete: () => bar$plete(),
})

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

相关推荐

  • angular - foo.subscribe with bar not always working - Stack Overflow

    Imagine we have foo$ and bar$ and both of them are BehaviorSubjects.I have a bug in angular that somet

    7天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信