Exception: ObjectUnsubscribedError when working with Observables with RxJS and Angular2

前端 未结 1 1142
野的像风
野的像风 2021-01-19 06:47

I am still trying to teach myself Angular2 (and I really need to find some better resources) but I have a question. I have moved my data calls to a service and I am using Re

相关标签:
1条回答
  • 2021-01-19 07:30

    I would subscribe to the loginInUser observable to be notified when the current user is updated:

    constructor(public userDataService: UserDataService) {
      this.userDataService.loginInUser.subscribe(
        (currentUser) => {
          console.log(currentUser);
        }
      });
    }
    

    Don't forget that an HTTP request is asynchronous so you can receive data after the constructor of your App component is executed.

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