Component variables inside a RxJS subscribe() function are undefined
<p>Variables inside subscribe are undefined but when I put breakpoint before hitting service subscribe I have the variable defined.</p>

<p>In Service:</p>

<pre class="lang-js prettyprint-override"><code>getCashierRiskProfiles(): Observable&lt;ICashierRiskProfile[]&gt; {
  return this.http.get(this._baseUrl + "src/HTTPJson/cashierriskprofile.json")
    .map((res: Response) =&gt; res.json())
    .catch((error: any) =&gt; Observable.throw(error.json().error || 'Server error'));
}
</code></pre>

<p>In Component:</p>

<pre class="lang-js prettyprint-override"><code>import { Component, OnInit } from "@angular/core";
import { Observable } from 'rxjs/Observable';

import { CashierRiskProfileService } from "./cashierriskprofile.service";
import { ICashierRiskProfile } from "../shared/interfaces";

@Component({
  selector: "cashierriskprofile",
  templateUrl: "../src/app/cashierriskprofile/cashierriskprofile.component.html"
})
export class CashierRiskProfileComponent implements OnInit {
  filterText: string;
  cashierRiskProfiles: ICashierRiskProfile[];

  constructor(
    private sorter: Sorter,
    private service: CashierRiskProfileService
  ) { }

  ngOnInit() {
    this.filterText = "Filter Exceptions:";
    //// Observable technique
    this.service.getCashierRiskProfiles()
      .subscribe(
        (riskProfiles) =&gt; {
          this.cashierRiskProfiles = riskProfiles;
          this.filterText = "Inside Subscribe:";
        },
        err =&gt; {
          // Log errors if any
          console.log(err);
        }
      );
  }
}
</code></pre>

<p>In above component code inside ngonInit() service call, this.cashierRiskProfiles inside the subscribe is undefined, but after I put breakpoint before the service callI have that variable available and defined.</p>

<p>I have seen lot of people having this issue with component variables with this.variablename getting undefined inside subscribe. When you notice this.filterText I can get the values assigned to it outside dataservice call, but when I put breakpoint inside subscribe, this.filterText is undefined and I don't know how I am losing it.</p>

<p>What's going on?</p>