Angularjs controller inheritance, commonly used is scope nesting scope. By default, when a property cannot be found in the current scope, it is searched in the parent scope, if not found until $rootscope.
But in some cases, Rootscope is our controller, it is impossible to write a large number of common property methods to Rootscope.
For example, there are a number of similar pages, there are crumbs, search bar, toolbars, tables and other elements, crumbs form such elements considered as directive, then there will be many similar configurations need to be transferred from controller to the component, there will be a lot of tool-class methods for processing data, It is obviously difficult to write the same code repeatedly in the controller of each page, and you need to use inheritance.
Found a solution on the StackOverflow, the original angularjs has taken into account this situation, providing a $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 is a small set to introduce the Angularjs controller inherited from another controller related knowledge, hope to help everyone!