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?
How to share data between two modules in AngularJS?
Asked Answered
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');
}
});
I have two modules.frontApp and departmentApp.I need to pass data from frontApp to departmentApp on click of some link.Do i have to use above code in both app.js? @Chimene –
Siegel
If the two modules belongs to the same app, this is the recommended way to transfer data. –
Chimene
I am having two different ng-app.Is it possible to send id from one app to another app by calling function? –
Siegel
Here is the link to my question.If you find some time plz go through.#46193964 –
Siegel
© 2022 - 2024 — McMap. All rights reserved.