what is the best way to do the following scenario:
In a component I have a function that builds an array like so:
var arr = ['a','b'];
In the parent controller, I want to be able to change this array if needed. I thought that I may use events for this: in PHP (using Laravel) I can call by reference a variable when listening on that event and by doing so, when I modify the variable inside the listen
block, the original variable gets updated to.
In angular, i tried to $emit
an event on the rootScope and listen on that event on the parent controller:
// directive controller
$rootScope.$emit('$genericColumns', arr)
// parent controller
$rootScope.$on('$genericColumns', function($event, arr) {
arr = [];
return arr;
});
But doing this, does not modify the original arr
variable.
What is the best way to accomplish this? How can i modify a variable in the child directive scope when needed?