Share services from plugins

Hi all I've one app plugin and one vis plugin, and I want to share an angularjs service that stores a variables and give the possibility to get or set it.
I can't achive this, seems that the service I've created is not a singleton or during routing it is resetted.
This is the code of service during deploy:

'use strict';

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var _uiModules = require('ui/modules');

var _uiModules2 = _interopRequireDefault(_uiModules);

_uiModules2['default'].get('app/report').service('imageService', function () {

  var imagePath = '';

  this.set = function (path) {
    imagePath = path;

  this.get = function () {
    return imagePath;

@valereds we generally don't store state in AngularJS services, as normal things like page refreshes will cause these to be lost. I'd recommend looking at how some of the core_plugins use AppState to track state.

I'd also avoid this as well since in theory people could install one plugin and not the other. I like to imagine each plugin being it's own fully enclosed piece.

Now that's not to say that we could get creative with the codebases of each plugin, where a shared library is perhaps brought in or used during build. A very simple solution is using npm and publishing a reusable library that both plugins depend on.

Maybe the solution to create a shared libraries is the best way to get wat I want.
Thank you all :slight_smile:

Session storage can also be a useful place to put things

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.