title: angular 2, return Observables according to if statement
body: <p>Hi I want create something like this. </p>
  
  <pre><code>someFunction():Observable&lt;Response&gt;{
    let response$ = new Observerable();
  
    if (...){
      response$ = this.http.get(url1)
    }else{
      response$ = this.http.get(url2)
    }
    return response$
  }
  </code></pre>
  
  <p>if I subscribe to it, i'm getting an error</p>
  
  <blockquote>
    <p>Cannot read property 'subscribe' of undefined</p>
  </blockquote>
  
  <p>Thanks for all the help in advance!</p>
  
  <p>EDIT---------
  this is the actual function using ionic 2 and cordova.
  It checks whether the app is on a mobile device or not and opens a popup with url (intend to be used for social logins)</p>
  
  <p>Once the window closed I will need to perfom a http.get request to fetch a token from my backend.</p>
  
  <pre><code>public social(providerName:string):Observable&lt;Response&gt;{
  
  let response$ = new Observable&lt;Response&gt;();
  let url =providerName+'/someUrl'
  
  let authWindow;
  
  if(window.cordova){
      let authWindow= InAppBrowser.open(url, '_blank', 'location=no');
  
      authWindow.addEventListener('loadstop', event =&gt; {
          if(event.url.indexOf(`${providerName}/callback`) &gt; -1){
              authWindow.close()
          }
      });
  
      authWindow.addEventListener('loaderror', event =&gt;{
          if(event.url.indexOf(`${providerName}/callback`) &gt; -1){
              authWindow.close()
          }
      });
  
      authWindow.addEventListener('exit', () =&gt; {
          setTimeout(()=&gt;{
               response$ = this.http.get(...)
          },500)
      })
  
  }else{
      authWindow = createWindow(popupUrl);
      let window = Observable.interval(1000);
  
      let  pingWindow = window.subscribe(
          ()=&gt;{
              if(authWindow.closed){
                  pingWindow.unsubscribe();
  
                  response$ = this.http.get(...)
  
              }
          })
  }
  
  return response$
  </code></pre>
  
  <p>}</p>