title: How to set a value from observable to a variable in Angular 2
body: <p>I have a <code>UsernameService</code> that returns an observable which contains a json object. In <code>AnotherService</code>, I want to inject a value from the <code>UsernameService</code> object.</p>
  
  <p>So far, I am able to subscribe to the observable from UsernameService and I can show it in the console.  I can even drill down and show one of the values from the object in the console.  However, I don't understand how to assign that value to a variable that I can then use.  Instead, when I try to assign the value to a variable, in the console I get: Subscriber <code>{closed: false, _parent: null, _parents: null...etc</code></p>
  
  <p>Here's my example where I am successfully showing the observable value in the console:</p>
  
  <pre><code>import { UsernameService } from './username.service';
  import { Injectable, OnInit } from '@angular/core';
  import 'rxjs/Rx';
  
  @Injectable()
  export class AnotherService {
  
      username: any[] = [];
  
      constructor(private getUsernameService: UsernameService) { }
  
      someMethod() {
          let myFinalValue = this.getUsernameService.getUsername()
          .subscribe(username =&gt; console.log(username.data[0].AccountName));
      }
  }
  </code></pre>
  
  <p>The code above results in the console correctly showing the value of the <code>AccountName</code> field which I am trying to  assign to the variable <code>myFinalValue</code>.  However, I cannot seem to figure out where I am going wrong. </p>
  
  <p>When I try to use the same  technique to simply  get the value (instead of log in console), I get the generic: Subscriber <code>{closed: false, _parent: null, _parents: null</code>...etc as I mentioned before.</p>
  
  <p>Here's an example of the code that results in my error:</p>
  
  <pre><code>import { UsernameService } from './username.service';
  import { Injectable, OnInit } from '@angular/core';
  import 'rxjs/Rx';
  
  @Injectable()
  export class AnotherService {
  
      username: any[] = [];
  
      constructor(private getUsernameService: UsernameService) { }
  
      someMethod() {
          let myFinalValue = this.getUsernameService.getUsername()
          .subscribe(username =&gt; this.username = username.data[0].AccountName);
          console.log(myFinalValue);
      }
  }
  </code></pre>
  
  <p>Ultimately, my goal is to just assign the value from <em>username.data[0].AccountName</em> to the variable <em>myFinalValue</em>.</p>
  
  <p>Thanks in advance for your help!</p>