Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angularjs - controller inheritance calling parent

I have a parent controller inside the first module and a "child" controller inside the second module. The second module has a dependancy to the first. I want my "child" controller to inherit the "parent" controller. But the problem is how to call the "parent" controller method.

For example:

 SecondModule.controller("childBrowseCtrl", function($scope, $injector, $controller){
        $injector.invoke(ParentBrowseCtrl, this, {$scope:$scope});

        //this overrides the onedit function from parent
        $scope.onEdit = function(){
            console.log("from edit console");

            //how do i make this work?
            ParentBrowseCtrl.$scope.onEdit();
        };

});

The html structure:

 <html>
   <head></head>

   <body>
      <div ng-view></div>
   </body>

   <script src="coreapp.js"></script>
   <script src="mainapp.js"></script>

   <script>
     angular.bootstrap(document,["MainApp"]);
   </script>

   </html>
like image 481
zPrima Avatar asked Oct 01 '22 23:10

zPrima


1 Answers

This may work:

var parentOnEdit = $scope.onEdit;

$scope.onEdit = function() {
    parentOnEdit();
};
like image 169
sp00m Avatar answered Oct 03 '22 14:10

sp00m