You can share data between controllers with the help of either a service or you can use $emit() and $broadcast() functions.
There is a listener function in AngularJS $on() which will always be listening to the broadcast and emit events.
The syntax for the above function :
$scope.$emit(‘name1’,{}); //here you can send your data
$scope.$broadcast(‘name2’,{});
$scope.$on(‘name2’,function(event,args){
});
When using a service you can simply inject the service into your two controllers and share the data.
.service('someService', function () {
var self=this;
self.language = '';
});
.controller('firstCtrl', function($scope, someService) {
$scope.setLanguage = function(language) {
$scope.language = language;
someService.language = language;
}
});
.controller('secondCtrl', function($scope, someService) {
$scope.language = someService.language;
});