title: Unsubscribe from Angular's Location service
body: <p>I'm using Angular's (v5.2.2) Location service to track URL changes in a specific component.</p>
  
  <pre><code>ngOnInit(): void {
      this.location.subscribe(event =&gt; {
          if (event.type === 'hashchange') {
              this.doSomething();
          }
      });
  }
  </code></pre>
  
  <p>I want to unsubscribe from the Location events when the component is destroyed.</p>
  
  <pre><code>ngOnDestroy(): void {
      this.location.unsubscribe();
  }
  </code></pre>
  
  <p>But I get the error:</p>
  
  <pre><code>this.location.unsubscribe is not a function
  </code></pre>
  
  <p>The problem is that the code continues to be executed when the URL is changed, even thought the page is different and this component is not even loaded.</p>
  
  <p>How can I unsubscribe from the Location events?</p>