How to share data between two modules in AngularJS?

后端 未结 1 654
遇见更好的自我
遇见更好的自我 2020-12-03 04:50

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 an

相关标签:
1条回答
  • 2020-12-03 05:45

    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');
        }
    });
    
    0 讨论(0)
提交回复
热议问题