如何在AngularJS中的两个模块之间共享数据?

前端之家收集整理的这篇文章主要介绍了如何在AngularJS中的两个模块之间共享数据?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用AngularJS以及c#mvc。我有一个主页,用户输入一些数据,并将其传递到第二个模块,我使用这些数据进行处理和决定。我必须使用第二个模块中第一个模块中输入或更新的数据。有人可以帮我怎么实现吗?
希望以下的实现将有助于您得到一些了解。
  1. angular.module('app.A',[])
  2. .service('ServiceA',function() {
  3. this.getValue = function() {
  4. return this.myValue;
  5. };
  6.  
  7. this.setValue = function(newValue) {
  8. this.myValue = newValue;
  9. }
  10. });
  11.  
  12. angular.module('app.B',['app.A'])
  13. .service('ServiceB',function(ServiceA) {
  14. this.getValue = function() {
  15. return ServiceA.getValue();
  16. };
  17.  
  18. this.setValue = function() {
  19. ServiceA.setValue('New value');
  20. }
  21. });

猜你在找的Angularjs相关文章