如何共享两个模块之间的数据在AngularJS? [英] How to share data between two modules in AngularJS?

查看:1144
本文介绍了如何共享两个模块之间的数据在AngularJS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用AngularJS用C#MVC一起。我在那里用户输入一些数据,并应传递到我使用这些数据进行处理和决定的第二模块主​​页。我必须使用第二模块内输入或更新的第一模块中的数据。有人可以帮助我如何实现这一目标?

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?

推荐答案

希望下面的实施将帮助你获得一定的了解。结果

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');
    }
});

这篇关于如何共享两个模块之间的数据在AngularJS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆