I am looking to create a common angular base controller with some custom methods, one of which allowing me to change the $scope of the controller (defaulting to $rootScope). All other controllers can implement this base controller. Can anyone provide any advanced examples or possibly some insight as to which direction I should take? Thank you!
1 Answer
I am looking to create a common angular base controller with some custom methods
All nested controllers inherit from the parent controllers. So this might be of use to you : https://stackoverflow.com/a/24971239/390330
can implement this base controller.
AngularJS favors composition over inheritance. If you do the controller inheritance (and not angular like in the previous example) you need to manage the $inject
in each controller to pass any parameters to the parent e.g.
class Base{
constructor(iNeedThisSevice){}
}
class Child extends Base{
static $inject = ['iNeedThisService'];
constructor(iNeedThisSevice){super(iNeedThisService);}
}