I have two different apps on the same page.
Can I share data between these two apps via a service (or any other way?)?
Or is this not possible?
(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.
Thanks!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With