title: AngularJs - $digest() iterations reached with $cookieStore
body: <pre><code>app.controller('appCtrl', function ($scope, $cookieStore) {
  $scope.$watch(function(){return $cookieStore.get('currentUser');},   function(newValue, oldValue){
      if(newValue !== oldValue){
              $scope.currentUser = $cookieStore.get('currentUser');
          }
      });
  });
  </code></pre>
  
  <p>I have developed the code above with the intention to watch value saved in $cookieStore. When user singed in successfully, the json object will be saved in $cookieStore, with the help of this $watch function, user information would display on the top corner of the page. </p>
  
  <pre><code>$cookieStore.put('currentUser', response);
  </code></pre>
  
  <p>I am having two issues with this solution:</p>
  
  <ol>
  <li>the $watch function does not update the $scope.currentUser as I was hoping to. It only gets updated when I refresh the whole web page.</li>
  <li>Somewhere in this solution, the $digest() functions was called repeatedly. I tried to resolve this problem by adding <strong>if(newValue !== oldValue){}</strong>, it does not work.</li>
  </ol>
  
  <p>If I change my solutions to use $cookies instead of $cookieStore, it seems to be all working as expected, but $cookies does not allow me to save a Json object, which is why I prefer to use $cookieStore instead. </p>
  
  <p>Any ideas? Really appreciated it!</p>