AngularJS函数继承

AngularJS函数继承,angularjs,inheritance,angularjs-scope,angular-ui,Angularjs,Inheritance,Angularjs Scope,Angular Ui,我有5个控制器的angular JS,我希望所有的子级都继承父级的所有功能(datetimepicker、autorefresh等,这是在父级控制器中预定义的)。我尝试使用rootscope,但没有得到解决方案。您可以在控制器中使用公共功能 var app = angular.module('angular', []); app.factory("common",function(){ return {}; }) app.controller('ChildCt

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

您可以在控制器中使用公共功能

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

您可以将通用功能引入服务/工厂,并在控制器中使用它

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

您可以将通用功能引入服务/工厂,并在控制器中使用它

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

您可以将通用功能引入服务/工厂,并在控制器中使用它

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