I have been experimenting with AngularJS values, and wish to store a global value for accessing and setting in different controllers.
So I have been trying out with the value approach like so:
var app = angular.module('myApp', []);
app.value('globalValue', 0);
app.controller('myCtrl', ['$scope', '$rootScope', 'globalValue', function($scope, $rootScope, globalValue) {
$scope.updateValue = function() {
globalValue++;
};
}]);
app.controller('myCtrlB', ['$scope', '$rootScope', 'globalValue', function($scope, $rootScope, globalValue) {
$scope.someValueB=globalValue;
}]);
Here's a fiddle
This is not working as I thought it might, so in my fiddle, when clicking the button to increment my 'global', the scope property in myCtrlB does not change.
I have clearly gone about this the wrong way, have I totally misunderstood how to use value()'s here?
Thanks