I have been working on an Angular factory that utilizes the revealing module pattern to expose a service interface. The factory relies on injected dependencies to support the public service, which are not explicitly included in the public service itself. While I understand why the code below is not functioning as expected, I am struggling to find a standard design pattern to address this issue. I am looking for guidance on how to access private members and functions when invoking the public service. If a controller calls myfactory.initData();
, the private functions and variables are currently inaccessible.
(function () {
'use strict';
angular.module('app').factory('myFactory', ['common', 'config', myFactory]);
function myFactory(common, config) {
var data = { cogs: [], widgets: [] };
var dep = config.dependency;
// Define the factory service
var service = {
data: data,
initData: initData,
reset: reset
};
return service;
function initData(forceRefresh) {
_private1(); // Currently out of scope, not part of the returned service
_private2(); // Currently out of scope, not part of the returned service
}
function _private1() {
// Access non-exposed private method to get cogs
dep.f1();
}
function _private1() {
// Access non-exposed private method to get widgets
dep.f2();
}
}
})();