how to access $rootscope variable in angularjs?

exAres picture exAres · Sep 19, 2013 · Viewed 18.3k times · Source

I want to assign some data to a global variable (may be $rootscope) which gets initialized at pageload. And then I want to access that data from all the controllers. How would I do that?

// Edit : I tried following and it works as expected....

function Ctrl1($rootScope) {
    $rootScope.value = "asdf";
}

function Ctrl2($rootScope, $scope) {
    $scope.value = $rootScope.value;
}

Answer

CodeSamurai777 picture CodeSamurai777 · Sep 19, 2013
MyController($rootScope,$scope)
{
  $rootScope = ....
}

you get the point :)