title: How to use subscribe in Angular2
body: <p>I want to retrieve all the orders placed by a customer.
  So, in my component I've written like below.</p>
  
  <pre><code>ngOnInit() {
      this.customerId = this.getCustomer();
      this.orderHistoryItems = this.getOrders();
  }
  
  getCustomer(): string {
      this._accountService.getCustomer()
          .subscribe((response) =&gt; {
              if (response.GeneralStatus.toString() === 'Success') {
                  return response.Result.CustomerId;
              }
          });
      return "";
  }
  
  getOrders(): OrderHistory[] {
  
      this._trackOrdersService.getOrders(this.customerId)
          .subscribe((response) =&gt; {
              if (response.GeneralStatus.toString() === 'Success') {
                  return response.Result;
              } 
          });
      return [];
  }
  </code></pre>
  
  <p><strong>When I invoke this, for the first time I'm getting the customerId as <code>undefined</code></strong>. Control is not even entering in if condition in <code>subscribe</code> in above <code>getCustomer()</code> method.
  If I reload the same page then I'm getting the customerId and orders as well. I've written respective http calls for <code>getCustomer</code> and <code>getOrders</code> like below.</p>
  
  <pre><code>getOrders(custId) {
      return this._http.get(`${this.apiUrl}GetOrders?CustomerID=${custId}`, { headers: this.headers })
          .retry(2)
          .map(function (res) {
              return res.json();
          });
  }
  
  getCustomer(): Observable&lt;ApiResponse&lt;Customer, string&gt;&gt; {
      return this._http.get('${this.apiUrl}LoggedInCustomer', { headers: this.headers })
          .retry(2)
          .map((response) =&gt; response.json())
          .catch(this.handleError);
  }
  </code></pre>
  
  <p>Please help me if there is any mistake in above code.</p>