LATEST UPDATE: 2019/07/16
The issue I am facing is actually a result of misusing $inject
. Instead of declaring it as private $inject
in api-service.ts
, it should have been public static $inject = [...]
. During the minification process, explicit injection is crucial but using private $inject
made it implicit.
I encountered a similar problem to this post. Instead of the unknown tProvider
, my error message specified the provider name as:
Unknown provider: eProvider <- e <- api-service <- baseDI-service
Both api-service
and baseDI-service
are named and registered services within the same module.
This is how my module is structured:
module
--api-service
--other-services
--baseDI-service
--componentA
----controllerA extends BaseController
--componentB
----controllerB extends BaseController
I imported api-service
and other services into baseDI-service
, which serves as a service container to avoid passing numerous parameters in super()
of component A, for example.
Within component A, the code looks like this:
...
class ComponentAController extends BaseController {
public static $inject = ['baseDI-service', ...];
constructor(baseDIService: BaseDIService) {
...
super(baseDIService);
...
}
}
BaseDIService.ts
:
export default class BaseControllerDIService {
public static $inject = ['api-service', '$http', ...];
constructor(
private apiSvc: ApiService,
private $http: ng.IHttpService,
...
) {}
public getBaseClassDependencies() {
return{
apiService: this.apiSvc,
$http : this.$http
... : ...
};
}
}
BaseController.ts
export default class BaseController implements ng.IComponentController {
apiService: ApiService;
$http: ng.IHttpService;
constructor(
baseDIService: BaseDIService
) {
const services = baseDIService.getBaseClassDependencies();
this.$http = services.$http;
this.apiSvc = services.apiService;
...
this.otherService = services.otherServices;
...
}
Upon Grunt Uglify minification, the error shifted to 'Unknown provider: serviceAProvider <- serviceA'. It worked fine without minification.
Prior to this approach, I also attempted to use $injector
in the same manner as baseDI-service
in controller A to pass it to super()
, and in BaseController I utilized $injector.get('api-service')
, resulting in the same issue only during minification.
If anyone can explain why both methods failed during Uglify minified mode and provide a solution, I would greatly appreciate it. Minification is necessary in my case.
Furthermore, is utilizing controller inheritance considered a good practice in AngularJS?