title: AngularJs - keeps getting old value of scope even if it is updated
body: <p>In my application, I'm retrieving some fields from the database and setting the values in local storage when a user logs in.</p>
  
  <p>and then retrieving from local storage to display it to user:</p>
  
  <pre><code>if (localStorage.getItem('a') != undefined) {
              $rootScope.a = localStorage.getItem('a');
      }
  </code></pre>
  
  <p>So this is working fine. But the problem is when the value gets updated in the database and user logs in after logging out, then even if the local storage has correct value (i.e., recently updated value), the first time it will display the old value of the scope variable which just got updated.</p>
  
  <p>I tried <code>$apply()</code> and also <code>$digest()</code> as suggested in different posts here :</p>
  
  <pre><code>$timeout( function () {
          $scope.$apply( function () {
              $rootScope.a = localStorage.getItem('a');
          });
      });
  </code></pre>
  
  <p>But it didn't work out. It always displays the old value of scope.
  It will only display the new value after reloading the page once.</p>
  
  <p>P.S. - The web page in my application won't be reloaded in any module, even when logging in and out.</p>