扩展控制器的特定功能

时间:2014-12-15 13:19:02

标签: angularjs

我有控制器(比如BaseCtrl),它附带了许多功能。我想将BaseCtrl扩展到共享其某些功能的其他控制器,但是,我只需要一个或两个函数(而不是BaseCtrl的所有函数)。我已经看过一些演示如何扩展控制器的帖子,但我想知道是否可以扩展特定的功能以及如何扩展它?

1 个答案:

答案 0 :(得分:2)

扩展我的评论:

 app.controller('parentCtrl', function($scope,$rootscope) {

$rootscope.myPerent = function () {
     //your code
         }

   });

app.controller('childCtrl', function($scope,$rootscope) {

    $scope.ourPerent = function () {
        $rootscope.myPerent();
   }

   });