title: ngOnDestroy works when open and closing component. Not when leaving website. Angular
body: <p>I've a component in my angular app that I would like to handle some information after the user leaves the website/app. </p>
  
  <p><strong>chat.component.ts</strong></p>
  
  <pre><code>  ngOnDestroy() {
      this.chatService.newUserCount.subscribe(data =&gt; {
        this.chatCount = data--;
      });
      this.chatService.removeUser();
      this.chatService.sendMessage('User has left');
      this.chatService.leaveChat('User left');
    }
  </code></pre>
  
  <p>I have a toggle button that shows/hides the above component. When closing the component ngOnDestroy() works and the code executes properly. But, when the user leaves the website, the code does not execute. What am I doing wrong? Am I doing this in the wrong code section?</p>