Organizational Research By

Surprising Reserch Topic

angular dependency injection with prototypal inheritance

angular dependency injection with prototypal inheritance  using -'javascript,angularjs,dependency-injection,angularjs-controller,prototypal-inheritance'

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


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.

asked Oct 11, 2015 by patilkiran.101
0 votes

Related Hot Questions

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.