Looking to consolidate common functionality in my controllers, I want to utilize inheritance in a parent controller instead of creating a service.
Most examples utilizing the $injector.invoke
function require the parent's constructor function to be accessible.
For example: http://plnkr.co/edit/kva82QyytKQfOafGiVxL?p=preview.
Since each of my controllers is stored in separate files, I aim to implement the following:
The parent controller resides within its own module:
angular.module('app.parent').controller('ParentCtrl', function() {
this.someMethodProvidedbyParent = ....
});
The child controller extends ParentCtrl
using $injector.invoke
. How do we access ParentCtrl
?
angular.module('app.parent.child').controller('ChildCtrl', function($injector) {
// We need to fetch ParentCtrl from the angular module 'app.parent'
$injector.invoke(ParentCtrl, this, {});
});
I could potentially place ParentCtrl in a global object, but I prefer leveraging the angular module system.