I have implemented a subscription in the ngOnInit() method of an Angular2 component and then unsubscribed in ngOnDestroy(). However, after reinitializing the component, I encounter the following error:
ObjectUnsubscribedError: object unsubscribed
The code snippet in my class is as follows:
ngOnInit() {
this.chatService.getConversationsEvent()
.subscribe((data:Data<Array<Conversation>>) => {
console.log('from correspondence');
});
this.scrollToBottom();
}
ngOnDestroy() {
this.chatService.getConversationsEvent().unsubscribe();
}