title: how to set a variable in an angular factory once it's available?
body: <p>I created a factory in angular that communicates with an API. For that API I need to pass in an 'x-token' custom header with every request, and that token is created in localstorage once a user has logged in.</p>
  
  <p>I notice that the factory thinks that the token is null, probably because the factory gets loaded before the users has logged in?</p>
  
  <p>Is there a way to populate this token in the factory after a user has logged in or is there a better way to handle this?</p>
  
  <pre><code>app.factory('apiFactory', ['$http', function($http){
      $http.defaults.headers.common['x-token'] = localStorage.getItem("token");
  </code></pre>
  
  <p>In the code sample above, the factory says that the x-token is null while it's definitely in localstorage.</p>