AngularJS controller inherits from another controller, and angularjs controller inherits
Controller inheritance in AngularJS, commonly used is the scope nested scope. By default, when an attribute cannot be found in the current scope, it will be searched in the parent scope. If it cannot be found until $ rootScope is found.
However, in some cases, rootScope is our controller, and it is impossible to write a large number of public attribute methods into rootScope.
For example, there are multiple similar pages with elements such as bread, search bar, toolbar, and table. The elements such as a bread table are considered as directive, there will inevitably be many similar configurations that need to be transferred from the controller to the component, and many tool-class methods will be generated for processing data, etc, at this time, it is difficult to repeatedly write the same code in the controller of each page, and inheritance is required.
The solution was found on StackOverflow. AngularJS has already considered this situation and provided $ controller
Var app = angular. module ('angularjs-starter ', []); app. controller ('parentctrl ', function ($ scope) {// I'm the sibling, but want to act as parent}); app. controller ('childctrl ', function ($ scope, $ controller) {$ controller ('parentctrl', {$ scope: $ scope}); // This works });
The above section describes the AngularJS controller inherited from another controller. I hope it will help you!