title: Angular 6 - logout when only browser close not on refresh
body: <p>I have tried to destroy the local storage to logout when the browser close in angularjs 6. Its working fine in browser close but also when refresh the page. I just need in browser close not in refresh</p>
  
  <p>Here is the code in <strong>.ts</strong></p>
  
  <pre><code>@HostListener('window:beforeunload', ['$event'])
    beforeunloadHandler($event) {
      localStorage.removeItem('userId');
    }
  </code></pre>