title: Ionic 2: stop an http request
body: <p>My provider makes available an API for an <code>http.get</code> request:</p>
  
  <pre><code>join(){
      let headers = new Headers();
      headers.append('Content-Type', 'application/json');
      headers.append('x-access-token',this.getToken());
      return Observable.create(observer =&gt;{
          this.http.get('/localhost/chat/'+this.room,{headers : headers})
                  .map(res =&gt; res.json())
                  .subscribe(
                      data=&gt;{                         
                          observer.next(data);
                      },
                      (err) =&gt;{
                          observer.error(err);
                      }
                  );
      })
  }
  </code></pre>
  
  <p>My <code>page.ts</code> just use this API cyclically:</p>
  
  <pre><code>join(){
      this.myProvider.join().subscribe(
          (data)=&gt;{
              if(data.success){
                  ... /* doing smt */ ....
                  this.join();
              }else{
                  this.message=data.message;
                  //TBD sleep....
                  //this.join();
              }
          },
          (err) =&gt; {
              this.message="Connectivity with server Lost...";
          });
    }
  </code></pre>
  
  <p><strong>My question is:</strong> I would like to write a function in <code>page.ts</code> in order to stop this cycle.
  How can I kill a pending get request?</p>
  
  <p><strong>A solution that doesn't work was</strong>
  I tried to keep a pointer to the observable object in my <code>page.ts</code>:</p>
  
  <pre><code>export class Page {
      ...
      join_channel: any;
    join(){
      this.join_channel = this.myProvider.join().subscribe(
          (data)=&gt;{
              ...
                  this.join();
              ...
  </code></pre>
  
  <p>Then I by calling the <code>this.join_channel.unsubscribe()</code> I wanted to close the request, so in my case:</p>
  
  <pre><code>  ionViewWillLeave() {
      this.join_channel.unsubscribe();
      delete this;
    }
  </code></pre>
  
  <p>But even by unsubscribing, the get request is still there pending; so when I try to enter again in my page, a new <code>join()</code> can't receive a http.get response at the first step, because the answer will be used before for the previous request which is still pending.</p>