title: Angular global factory
body: <p>I created a factory that I would like to use in different pages:</p>
  
  <pre><code>var sessionApp = angular.module('sessionApp', ['LocalStorageModule']);
  
  sessionApp.config(function(localStorageServiceProvider)
  {
  localStorageServiceProvider
      .setPrefix('mystorage')
      .setStorageType('localStorage');
  
  });
  
  sessionApp.factory('SessionFactory', function(localStorageService)
  {
  var service = {};
  var _store = 'session';
  
  service.load = function()
  {
      var session = localStorageService.get(_store);
  }
  
  service.save = function(data)
  {
      localStorageService.set(_store, JSON.stringify(data));
  }
  
  service.delete = function()
  {
      localStorageService.remove(_store);
  }
  
  return service; 
  });
  </code></pre>
  
  <p>Then I would add it on apps run method where I would assign it to the $rootScope.  I left that part of the code commented out for now.</p>
  
  <pre><code>var loginApp = angular.module("loginApp", []);
  
  loginApp.run(function($rootScope, SessionFactory)
  {
  //$rootScope.sessionFactory = SessionFactory;
  
  $rootScope.$on('$routeChangeStart',
  function(ev, next, current)
  {
  
  });     
  });
  </code></pre>
  
  <p>My error is:</p>
  
  <blockquote>
    <p>Unknown provider: SessionFactoryProvider &lt;- SessionFactory</p>
  </blockquote>
  
  <p>Is it because my factory is from sessionApp and my login module is loginApp?  Does that mean that I need to have the variables named the same like below:</p>
  
  <p>File: login.js</p>
  
  <pre><code>var myApp = angular.module("loginApp", []);
  
  myApp.run(function($rootScope, SessionFactory)
  {
  //$rootScope.sessionFactory = SessionFactory;
  
  $rootScope.$on('$routeChangeStart',
  function(ev, next, current)
  {
  
  });     
  });
  </code></pre>
  
  <p>File: session.js</p>
  
  <pre><code>myApp.config(function(localStorageServiceProvider)
  {
  localStorageServiceProvider
      .setPrefix('mystorage')
      .setStorageType('localStorage');
  
  });
  
  myApp.factory('SessionFactory', function(localStorageService)
  {
  var service = {};
  var _store = 'session';
  
  service.load = function()
  {
      var session = localStorageService.get(_store);
  }
  
  service.save = function(data)
  {
      localStorageService.set(_store, JSON.stringify(data));
  }
  
  service.delete = function()
  {
      localStorageService.remove(_store);
  }
  
  return service; 
  });
  </code></pre>