How to share data between two modules in AngularJS? How to share data between two modules in AngularJS? angularjs angularjs

How to share data between two modules in AngularJS?


Hope the following implementation will help you to get some understanding.

angular.module('app.A', []).service('ServiceA', function() {    this.getValue = function() {        return this.myValue;    };    this.setValue = function(newValue) {        this.myValue = newValue;    }});angular.module('app.B', ['app.A']).service('ServiceB', function(ServiceA) {    this.getValue = function() {        return ServiceA.getValue();    };    this.setValue = function() {        ServiceA.setValue('New value');    }});