title: When do Angular 2 services initialize
body: <p>I have a shared service that I am using to store global variables like authentication tokens.  I am having issues ensuring that the value is getting updated and that the newest value is being used in my components.  For example:</p>
  
  <pre><code>import {Injectable} from '@angular/core';
  
  @Injectable()
  export class GlobalVariablesProvider {
  
    private auth_token: string;
  
    constructor() {}
  
    getAuthToken() {
      return this.auth_token
    }
  
    setAuthToken(auth_token) {
      this.auth_token = auth_token
    }
  }
  </code></pre>
  
  <p>and then in my <code>login-component</code> I set the <code>auth_token</code>:</p>
  
  <pre><code>this.clientService.login(user).subscribe(
    successData =&gt; {
      this.current_user = successData["user"]
      this.globalService.setAuthToken(this.current_user.auth_token)
    }
  }
  </code></pre>
  
  <p>but when I navigate to a different page / use a new component, occasionally the <code>auth_token</code> is out of sync (I believe if the service is being re-initialized and losing the <code>auth_token</code> value).</p>
  
  <pre><code>this.auth_token = this.globalVarService.getAuthToken()
  // occasionally returns null
  </code></pre>
  
  <p>Is there a way to ensure that nce this variable is set, the value remains even after being injected into another component?</p>