According to Todd Motto's styleguide, Controllers chapter:
Inheritance: Use prototypal inheritance when extending controller classes
I try to implement it in my controllers:
function BaseController(){
'use strict';
this._path = '';
this._restService = undefined;
}
/**
* Boring JSDocs
*/
BaseController.prototype.getById = function(id) {
return this._restService.getById(this._path, id);
};
TagModalController.prototype = Object.create(BaseController.prototype);
/**
* Even more boring JSDocs
*/
function TagModalController(CommunicationService, $modalInstance, mode,
id, CommandService) {
'use strict';
// boring assertions
this.setPath('tags');
this.setRestService(CommunicationService);
But, as you can see, I have to always set restService which is needed in BaseController for communication with server side. Is any possibility to inject it like CommunicationService is injected into TagModalController? Then my code will look like this:
function BaseController(CommunicationService){
'use strict';
this._path = '';
this._restService = CommunicationService;
}
And method this.setRestService(CommunicationService); won't be needed anymore. Is there any way to achieve Angular DI with prototypal inheritance for controllers in AngularJS? Thank you in advance for every answer.