Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to share data between two modules in AngularJS?

Tags:

I am using AngularJS along with c# mvc. I have a home page where user enters some data and that should be passed to the second module where I use this data for processing and decisions. I have to use the data entered or updated in the first module within the second module. Can someone help me how to achieve this?

like image 324
KDKR Avatar asked Oct 27 '14 18:10

KDKR


People also ask

How can we share the data between controllers in AngularJS?

Approach: To share data between the controllers in AngularJS we have two main cases: Share data between parent and child: Here, the sharing of data can be done simply by using controller inheritance as the scope of a child controller inherits from the scope of the parent controller.

How do I pass data from one module to another in angular 11?

You can import MemberCardModule into AppModule directly. Or import into ShareModule and import ShareModule into AppModule. It is important to import Modules into AppModule. And then you can you MemberCardModule.


1 Answers

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');     } }); 
like image 111
Aviro Avatar answered Oct 11 '22 13:10

Aviro