Reputation: 7951
I have two controllers in two separate modules (and in two separate .js files), the html is like this:
<div ng-controller="ParentCtrl as parent">
.
.
.
<div ng-controller="ChildCtrl as child">
<table>
.
.
.
</table>
</div>
<button ng-click="parent.cancel()">Cancel</button>
</div>
My objective is to empty the table, inside the ChildCtrl scope, whenever the cancel button is clicked. I have the deleteAll() method in ChildCtrl that empties the table, however, I want that method to be invoked from inside of ParentCtrl.cancel(). Based on some research I've made, although I don't have a working solution, I have these options:
(1) Use a service (although as far as the examples I've seen, only data are shared by service, and not methods)
(2) Use $rootscope
(3) Use $broadcast (with $rootscope again)
What will be the best approach for this and how to do it?
Upvotes: 0
Views: 269
Reputation: 1542
have you referred this below link which has working demo and it uses $broadcast
angularJS: How to call child scope function in parent scope
Hope it helps...
Upvotes: 2