I try to factor out some common functionality between some of my controllers into a parent controller. I'd like to do this using some sort of inheritance, instead of some sort of service.
All examples using the $injector.invoke function rely on the parent's constructor function being in scope.
Like this: http://plnkr.co/edit/kva82QyytKQfOafGiVxL?p=preview.
Since I have all my controllers in separate files, I'd like to do something like this:
The parent controller has its own module:
angular.module('app.parent').controller('ParentCtrl', function() {
this.someMethodProvidedbyParent = ....
});
The child controller extends ParentCtrl using $injector.invoke. How to get ParentCtrl?
angular.module('app.parent.child').controller('ChildCtrl', function($injector) {
// Somehow need to get ParentCtrl from the angular module 'app.parent'
$injector.invoke(ParentCtrl, this, {});
});
I assume I could just place ParentCtrl in some object on the global scope, but I'd rather use the angular module system.
$controllerdependancy,$controller('ParentCtrl', {this: this});should work in child controller