When it comes to AngularJS services in TypeScript, I find that dependency injection can be quite cumbersome. Currently, I am defining a factory method within my service class and having to repeat all dependency injection arguments three times:
class MyService {
public static Factory($rootScope, myController) { // 1st time
return new MyService($rootScope, myController); // 2nd time
}
constructor(public $rootScope, public myController) {} // 3rd time
}
myModule.factory('myService', MyService.Factory);
I have attempted the following approach, but it does not seem to work as expected:
class MyService {
constructor(public $rootScope, public myController) {} // only once
}
myModule.factory('myService', MyService);
While this simplified way works well for controllers, it seems to fall short for services. Is there a more effective way to handle this?
Your input is greatly appreciated!