title: Ionic, Phonegap, AngularJs : local storage undefined key when emulating
body: <p>I just built a simple application calling a rest api built with symfony and secured with fos_oauth.</p>
  
  <p>I have a AuthService that return an access token that allow my mobile application to access to my api.</p>
  
  <p>It is stored in local storage :</p>
  
  <p><img src="https://i.stack.imgur.com/dUrrB.png" alt="Local storage"></p>
  
  <p>On my browser using ionic serve (similar to phonegap serve) the application is perfectly working and i can access to my variable stored locally. When emulating with ios, it is perfectly working. But when emulating with android or displaying my app on my phone with phonegap app. I can't access to those variables. Does that sound normal to you?</p>
  
  <blockquote>
    <p>[phonegap] 404 <a href="http://ynd.dev/api/login?access_token=undefined" rel="nofollow noreferrer">http://ynd.dev/api/login?access_token=undefined</a></p>
  </blockquote>
  
  <p><img src="https://i.stack.imgur.com/9XAOy.png" alt="Android vs Ios"></p>
  
  <p><strong>index.html :</strong></p>
  
  <pre><code>&lt;!-- Utils --&gt;
  &lt;script src="js/service/LocalStorageService.js"&gt;&lt;/script&gt;
  
  &lt;!-- JS Config --&gt;
  &lt;script src="js/functions.js"&gt;&lt;/script&gt;
  &lt;script src="js/config/parameters.js"&gt;&lt;/script&gt;
  
  &lt;!-- your app's js --&gt;
  &lt;script src="js/app.js"&gt;&lt;/script&gt;
  &lt;script src="js/config/routing.js"&gt;&lt;/script&gt;
  &lt;script src="js/service/AuthService.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p><strong>LocalStorageService.js :</strong></p>
  
  <pre><code>setObject: function(key, value) {
      $window.localStorage.setItem(key, JSON.stringify(value));
  },
  getObject: function(key) {
      return JSON.parse($window.localStorage.getItem(key) || '{}');
  }
  </code></pre>
  
  <p><strong>parameters.js :</strong></p>
  
  <pre><code>// Resources
  var domain = 'http://ynd.dev';
  var public_id = '4_4spkzm1pubcw40og04okk4wogs0cc44wkgkkoco88k8cwgkwgs';
  var secret = '28es09ymlcg0wgskgs4cso0co0ok0ww0gw8g0k8g4kcowckcco';
  
  // Access token
  var access_token = '';
  var identity_token = '';
  </code></pre>
  
  <p><strong>app.js :</strong></p>
  
  <pre><code>var app = angular.module('ionicApp', ['ionic', 'ionic.utils', 'ngResource']);
  
  app.run(function($ionicPlatform,$rootScope, $localStorage, $location, AuthService) {
  
    $ionicPlatform.ready(function() {
      // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
      // for form inputs)
      if(window.cordova &amp;&amp; window.cordova.plugins.Keyboard) {
        cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      }
      if(window.StatusBar) {
        StatusBar.styleDefault();
      }
  
      access_token = $localStorage.getObject('access_token');
      identity_token = $localStorage.getObject('identity_token');
  
      AuthService.token();
  
    });
    $rootScope.$on('$stateChangeStart', function (event, next) {
  
      access_token = $localStorage.getObject('access_token');
      identity_token = $localStorage.getObject('identity_token');
  
      AuthService.token();
  
      // IF no user logged
      if(isObjectEmpty(identity_token)){
  
        $location.path( "/login" );
  
      }
  
    });
  });
  </code></pre>
  
  <p><strong>AuthService:</strong></p>
  
  <p>This is how the object is stored in local.</p>
  
  <pre><code>$localStorage.setObject('access_token', {
                              key: res.data.access_token,
                              type: 'anonymous',
                              expires_at: Date.now()+(res.data.expires_in*1000)
                          });
  </code></pre>
  
  <p>Any ideas or hints?</p>
  
  <p><strong>UPDATE : (CORS)</strong></p>
  
  <pre><code>allow_origin: ['*'] 
  allow_headers: ['*'] 
  allow_methods: ['POST', 'PUT', 'GET', 'DELETE', 'OPTIONS']
  </code></pre>