title: How to unsubscribe immediately after the the condition is met in RxJs
body: <p>I am new to the RxJs observables and I am finding difficulty in unsubscribing the loop once the criteria are met, can you please help me</p>
  
  <p>In the below function if anytime the code reaches the if block I wanted to unsubscribe the Observables</p>
  
  <p>Before asking this questions I have gone through below questions and none of them helped me much</p>
  
  <ol>
  <li><a href="https://stackoverflow.com/questions/45754771/rxjs-observable-wait-until-some-condition-is-met">Rxjs observable wait until some condition is met</a></li>
  <li><a href="https://stackoverflow.com/questions/36129726/angularjs-rxjs-observable-unsubscribe">AngularJs - RXJS Observable unsubscribe</a></li>
  </ol>
  
  <p><strong>Javascript Function</strong></p>
  
  <pre><code>this.router.events.subscribe((url: any) =&gt; {
      url = this.router.url;
      if ((url === "/profile" || url === "/summary") &amp;&amp; this.filterConfigFlag === false) {
  
          /*
          Perform operations
          */
  
      } else {
          console.log(typeof (url), url);
  
      }
  });
  </code></pre>