是否可以共享两个angularjs应用程序之间的数据?

编程入门 行业动态 更新时间:2024-10-26 19:26:24
本文介绍了是否可以共享两个angularjs应用程序之间的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有相同的页面上有两个不同的应用程序。

I have two different apps on the same page.

我可以通过一个服务共享这两个应用程序之间的数据(或任何其他方式?)?

Can I share data between these two apps via a service (or any other way?)?

或者,这是不可能的?

(我怀疑的是,这是不可能的,虽然规则的角度机制) - 但我认为这仍然是值得问...

(my suspicion is that this is not possible though regular angular mechanisms) - but I thought it would still be worth to ask...

这可以使用窗口变量来实现 - 但我想避免这样做。

This can be done using the window variable - but I want to avoid doing so.

谢谢!

推荐答案

我最终解决它以下列方式:

I eventually solved it in the following manner:

angular.module('sharedService', []).factory('SharedService', function() { var SharedService; SharedService = (function() { function SharedService() { /* method code... */ } SharedService.prototype.setData = function(name, data) { /* method code... */ }; return SharedService; })(); if (typeof(window.angularSharedService) === 'undefined' || window.angularSharedService === null) { window.angularSharedService = new SharedService(); } return window.angularSharedService;}); /* now you can share the service data between two apps */ angular.module("app1", ['sharedService']) /* module code */ angular.module("app2", ['sharedService']) /* module code */

我不得不承认的事实,这种解决方案并不理想 - 但这是我发现这个问题的干净的解决方案。

I have to admit the fact that this solution is not ideal - but this is the cleanest solution I found for this problem.

更多推荐

是否可以共享两个angularjs应用程序之间的数据?

本文发布于:2023-07-23 19:29:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1199668.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   两个   数据   angularjs

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!