title: How to get variables inside a RxJS subscribe() function?
body: <p>I'm working with angular2.
  Now, I'm in trouble to get a value inside subscribe().
  I know it will return null.
  How can I return the correct value?</p>
  
  <p>Here's my code. Anyone give me advice, it would be very helpful. Thank you :)</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>this.deliveryService.deliveryCancel(rowInfo.branchId, rowInfo.id).subscribe(
                res =&gt; {
                  var data = res.json();
                  this.getDeliveryList();
                  this.msgs.push({ severity: 'success', summary: 'Info', detail: rowInfo.deliveryStatus });
                },
                err =&gt; {
                  this.errMessage = &lt;any&gt;err;
                  this.msgs.push({ severity: 'error', summary: 'Error', detail: this.errMessage });
                }
              );
              
              console.log(data);</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>deliveryCancel()</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code> deliveryCancel(branchId, deliveryId) {
      const headers = new Headers({
        'Content-Type': 'application/json'
      });
      return this.http.put(this.testUrl + '/admin/branches/' + branchId + '/deliveries/' + deliveryId + '/cancel', {
        headers: headers
      })
        .catch(handleError);
    }</code></pre>
  </div>
  </div>
  </p>