AngularJS 函数继承

AngularJS function inherit

我有 angular 带有 5 个控制器的 JS,我希望所有子级都继承父级的所有功能(datetimepicker、autorefresh 等。这是在父级控制器中预定义的)我尝试使用 rootscope 但没有找不到解决方案

您可以将通用功能引入 service/factory 并在控制器中使用它

var app = angular.module('angular', []);

    app.factory("common",function(){
     return {};
    })

   app.controller('ChildCtrl', function($scope, $controller,common) {

    });

或者你可以像这样从控制器继承

var app = angular.module('angular', []);

    app.controller('ParentCtrl ', function($scope) {
      ctrl to act as parent
    });

    app.controller('ChildCtrl', function($scope, $controller) {
      $controller('ParentCtrl', {$scope: $scope}); 
    });