How do I use $rootScope
to store variables in a controller I want to later access in another controller? For example:
angular.module('myApp').controller('myCtrl', function($scope) {
var a = //something in the scope
//put it in the root scope
});
angular.module('myApp').controller('myCtrl2', function($scope) {
var b = //get var a from root scope somehow
//use var b
});
How would I do this?
If it is just "access in other controller" then you can use angular constants for that, the benefit is; you can add some global settings or other things that you want to access throughout application
and then access it like:
(didn't test)
more info: http://ilikekillnerds.com/2014/11/constants-values-global-variables-in-angularjs-the-right-way/
first store the values in $rootScope as
$rootScope is the parent of all $scope, each $scope receives a copy of $rootScope data which you can access using $scope itself.