Overriding in angularjs

474 Views Asked by At

I have two controllers which are nested:

Controller A {

   $scope.submitForm = submitForm;

}

And

Controller B {

   function submitForm() {

      //Will this method be invoked? When there is a submit event fired in controller A?

   }

}

Note: Controller A and B are nested, i.e B is inside A.

2

There are 2 best solutions below

0
Aaron Rabinowitz On

Try using this: in controller b

$rootScope.$on('myFunctionInContollerb', function () {

});

in the controller calling the function

$rootScope.$broadcast('myFunctionInContollerb')

this is probably the easiest way to communicate in between controllers

0
d3l33t On

If you're using angular 1.6 or greater I encourage you to check out the component method instead of controller. Controllers using scope inheritance are considered legacy approach. Components even have example for child components using routes.

https://docs.angularjs.org/guide/component