Frage

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;
}
War es hilfreich?

Lösung

MyController($rootScope,$scope)
{
  $rootScope = ....
}

you get the point :)

Andere Tipps

If you are trying to show the variable in the view, there is not need of assign the variable from $rootScope to $scope.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top