Hello I have the following situation
I have a controller with a Method, that sets a timeout and calls a modal along with other actions:
angular
.module('app')
.controller('GlobalController', GlobalController);
function GlobalController($scope, $rootScope, ....) {
var vm = this;
$scope.$on("callMethod", function(){
vm.showModal();
});
}
I want to be able to access to that specific showModal() method from any other controller in the application
So I have the following options
$emit(name, args);
Dispatches an event name upwards through the scope hierarchy notifying the registered $rootScope.Scope listeners.
Using $emit
I have to define the GlobalController
as parent since its "upwards"
And:
$broadcast(name, args);
Dispatches an event name downwards to all child scopes (and their children) notifying the registered $rootScope.Scope listeners.
For any of those solutions i have to explicitly define the controller within the application (i mean on the view) in order to use it be as a parent or child, is there any way to do this, (even if it's not a controller)?