Using $emit To Pass A Function From Child To Parent In Angularjs
I want to send the result of a function to a parent controller from a child. Here is my file structure -submission.controller.js --calculate.controller.js In calculate.controller.
Solution 1:
Assuming the controllers are used in such a way that they are parent-child of each other, you have two issues with the code you have provided:
$scope.$emitexpects arguments next to event name so if you want to pass a function's result, you can have a seperate function and then call it from there like$scope.$emit('validForm', myFunctionCall())Also, you can't use
$scope.$onlike that since it doesn't return anything. If you want to access the values sent from$emit, you can do that inside the listener function (second argument) i.e. something like this:$scope.$on('validForm', function(event, argument1) { // argument1 is the same as return value of myFunctionCall() });
Post a Comment for "Using $emit To Pass A Function From Child To Parent In Angularjs"