title: Return value from callback function in service to component
body: <p>I'm using the Cordova  <a href="https://github.com/hoerresb/WifiWizard" rel="nofollow noreferrer">WifiWizard Plugin</a> in my Ionic 2 mobile app. Everything works fine, when I run it in the *.ts file of my page. In this case my code looks like:</p>
  
  <p><strong>Declaring WifiWizard</strong> before @Component:</p>
  
  <pre><code>declare var WifiWizard:any;
  </code></pre>
  
  <p><strong>Call of WifiWizard and success / error methods:</strong></p>
  
  <pre><code>setCurrentWifiAsHomeWifi() {
    WifiWizard.getCurrentSSID(this.ssidSuccess, this.ssidError);    
  }
  
  ssidSuccess = (ssid) =&gt; {
     this.userService.setHomeWifi(this.user.$key, ssid);
  };
  
  ssidError = (err) =&gt; {
    console.log("WiFi Wizard Error"+err);
  };
  </code></pre>
  
  <p>However, I don't want to put all this wifi-logic in the page-component, but move it to a wifi provider / service instead. But I don't get this service to return the ssid-string to the component.</p>
  
  <hr>
  
  <p><strong><em>EDIT:</em></strong></p>
  
  <p>I tried many different things and I carefully read the post, linked by gyre (thank you for that). However, I still can't figure out a solution for my problem, and I think it's slightly different to the linked question.</p>
  
  <p>Let me sketch the structure of my problem to make it more obviously to you:
  <a href="https://i.stack.imgur.com/8HBUR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8HBUR.png" alt="structure of my serviceCall"></a></p>
  
  <p>I'm calling the wifiService from homePage.ts, e.g. using a promise:</p>
  
  <pre><code>setCurrentWifiAsHomeWifi() {
    this.wifiService.loadWifiData().then( result=&gt; {
    console.log("returned SSID: "+result);
  });
  </code></pre>
  
  <p>In wifiService.ts I need to implement "loadWifiData" which calls the wifiWizard plugin like this:</p>
  
  <pre><code>WifiWizard.getCurrentSSID(this.getWifiSuccess, this.getWifiError);
  </code></pre>
  
  <p>If this is successful, it passes the SSID-string to the "getWifiSuccess" method, if it fails it passes the error to "getWifiError". However the plugin call doesn't return any value to my homePage.</p>
  
  <p>How can I return the outcome (SSID or error) to my homePage? I'm stuck here. Appreciate your help! Hope it became clearer now.</p>