Issue with RxJs BehaviorSubject's subscriber not being notified of value change

前端 未结 2 575
误落风尘
误落风尘 2020-12-19 13:20

I am trying to use a RxJS BehaviorSubject that contains a boolean representing whether or not a user is connected/logged in the application.

<
相关标签:
2条回答
  • 2020-12-19 13:48

    I usually provide SessionService at bootstrap (and not with providers: []) to make sure you share one global SessionService instance throughout the entire app.

    bootstrap(AppComponent,
                [SessionService]);
    
    0 讨论(0)
  • 2020-12-19 14:04

    It seems like you have multiple instances of SessionService. e.g. you provided it more than once and the instance that you call signin in is not the same instance as the one you injected in NavbarComponent.

    It depends on your project design how you provide your services. Usually session services are singletons.
    I recommend removing providers: [SessionService], from NavbarComponent.

    0 讨论(0)
提交回复
热议问题