0

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 1

2

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);}
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.