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.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.