I am trying to call a function inside a controller which is in another controller inside another js file.
I have tried $broadcast
and $emit
but I think it works only inside the same file.
I have a controller called videoWidgetController
which has the function named clickVideoWidgetListItemFromDOM
.
I need to call it from my another controller named videoController
.
In this file, I am calling the function on click event like data-ng-click="clickVideoWidgetListItemFromDOM(video, $index)"
videoController
$scope.clickVideoWidgetListItem = function(video, index) {
$scope.$emit("myEvent"); *** didn't work for me ***
$rootScope.$broadcast("myEvent", {video: video,index: index }); *** didn't work for me ***
};
videoWidgetController
$scope.$on("myEvent", function (event, args) {
alert(1);
console.log(args);
$scope.clickVideoWidgetListItemFromDOM();
});
I was trying as mentioned in this link but, couldn't get the solution.
I searched a lot but unfortunately still in the same problem.