0

I want to store a date string in $rootScope but as soon as I do it throws infinite digestion errors.

   $rootScope.lastWeek = '2015-12-03';
   $rootScope.yesterday = '2015-12-09';

Why can't I do that?

EDIT:

.run(function ($window, $rootScope, $state, LoginService) {
    $rootScope.$on("$stateChangeStart", function (event, toState, toParams, fromState, fromParams) {
        $rootScope.user = angular.fromJson($window.sessionStorage.user);
        $rootScope.loggedIn = $window.sessionStorage.loggedIn;
        // Calendar options and attributes Datepicker date format
        $rootScope.lastWeek = '2015-12-03';
        $rootScope.yesterday = '2015-12-09';         
    });
});

Problem

I was using $rootScope.lastWeek in the view for a datepicker which had a $watch triggering a infinite digestion error. I just made a $scope variable equal my rootscope variable and using that in the view instead.

user1842315
  • 307
  • 3
  • 13
  • Storing those to rootscope doesn't sound like the right plan. And I'm guessing it's got to do with the way you declare directives. Remember, in the html / template, the directive is identified ``, but on the javascript side, it's converted to `myDirective`... – random_user_name Dec 10 '15 at 21:21
  • 1
    Where are you putting this? – Ignacio Chiazzo Dec 10 '15 at 21:21
  • 2
    The problem is elsewhere: http://plnkr.co/edit/pIzfWttimRhjmPt5bpfo?p=preview. Post a complete minimal example reproducing the problem. – JB Nizet Dec 10 '15 at 21:24

1 Answers1

1

how about create new Date() object

angular.module('app', []).run(function($rootScope) {
  $rootScope.lastWeek = new Date('2015-12-03');
  $rootScope.yesterday = new Date('2015-12-09');
});