javascript - How to invoke functions from nested controllers in Angular? -


in angular application, want invoke function nested controller. example, below want in current view of container, has own containerctrl lets say, able press button invoke function called 'buttonpress' defined in ctrl1 controller. right now, can't since, not defined within containerctrl scope.

html:

<div id="container">     <button ng-click="ctrl1.buttonpress()">i want press this</button>     <div ng-controller='ctrl1'>     <div ng-controller='ctrl2'> </div> 

is there way invoke function?

so want call buttonpress() method in child controller parent controller,in case containerctrl ctrl1. can call methods of parent controller child controller.

why want to call parent controller.why not directly define parent , call parent or child controllers.

one way of doing can use emit , broadcast.

check out link know more emit , broadcast

working $scope.$emit , $scope.$on


Popular posts from this blog