title: Angular access to data outside of a method that subscribes to an observable
body: <blockquote>
    <p>I want to be able to get access to data outside of my method with .subscribe</p>
  </blockquote>
  
  <p>This is my Service which "works" fine</p>
  
  <pre><code>getSessionTracker(): Observable&lt;ISessionTracker[]&gt; {
      return this.http.get(this._url)
          .map((res: Response) =&gt; {
              let data = res.json();
              return data;
          })
         .catch(this.handleError)
  } 
  </code></pre>
  
  <p><strong>Component is where my trouble is</strong></p>
  
  <pre><code>sessionTrackers: ISessionTracker[] = [];  //  object array 
  
  this.trackerService.getSessionTracker()
      .subscribe((sessionTrackers: ISessionTracker[]) =&gt; {
          this.sessionTrackers = sessionTrackers;
          console.log('real data in subscribe', this.sessionTrackers[0].SessionId);
      },
      (err: any) =&gt; console.log(err),
      () =&gt; console.log('getSessionTracker()'));
  </code></pre>
  
  <p>// outside of function this does NOT work</p>
  
  <pre><code> console.log('real data', this.sessionTrackers);
  </code></pre>
  
  <p><strong>2 problems</strong></p>
  
  <ol>
  <li>console.log INSIDE method with .subscribe works if I do a console.log,  however with <code>this.sessionTrackers[0].SessionId</code>   it is undefined , but <code>this.this.sessionTrackers</code></li>
  <li>this data not working outside of method  </li>
  </ol>
  
  <p>How can I persist the data?</p>