If the only reason you need these "classes", which should be angular Services, is to painlessly inject your dependencies, you can use $injector.instantiate to create them without registering as services.
Code example:
var PrivateClass = (function () { function PrivateClass($log) { this.hello = function () { $log.debug("Hello World!");} } PrivateClass.$inject = ["$log"]; return PrivateClass; })(); angular.module('TestApp', []).run(['$injector', function ($injector) { var p = $injector.instantiate(PrivateClass); p.hello(); }]);
You would use $injector.instantiate(PrivateClass) in the constructor (or anywhere) in the services it needs to create an instance of PrivateClass. If you want PrivateClass to behave as a singleton (for example, the real angular service), you could use the accessor class, which instantiates a single instance and returns a reference to callers.
The advantage of this is that you do not need to pollute the instance service (in this case, the function is passed to angular.run), an array of dependencies with the dependencies that are necessary so that they can be passed to PrivateClass ($ enter this case).
I noticed that this is a question for a year, but I found it, looking for a way to achieve just that and ultimately solve it using this approach.
source share