Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

243
Vistas
How can I call a function on another controller in a different directory from a controller is another directory where just copying it will not work?

So, I know there are other solutions here... but my situation is kind of unique.

The first controller, and yes, this is in AngularJS for a huge telecom, has several unique $scope variables which cannot be moved or copied. This code is a MESS!

So, I've tried:

        $rootScope.CallMainFunction, (incomingData) => {
             $scope.mainFunction(incomingData);
        };

and the mainFunction is here... all complex but I've dumbed it down

$scope.mainFunction = (data) => {

    --- Do lots of stuff here with lots of variables NOT available anywhere else

}

The calling function:

$rootScope.$emit.CallMainFunction(id);

The two controllers are separated by two folders:

--- MODULES (just the name of the directory)
---| folder 1
---| folder 2
---| folder 3
---| folder 50 <-- YEAH there are this many.

I COULD make a service but this is such a dysfunctional app, it'll take weeks. That's the CORRECT way to do it "IF" I was in Angular 6 - 14.

So, I'm left with trying to call a function to a function within another controller. Thoughts please?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Assuming the 'sending' controller is a parent of the 'receiving' controller (being that it's sent via $rootScope), you can broadcast the event down and then execute the function in it's own controller.

//broadcast the event down
$rootScope.CallMainFunction = function (someData) {
    $scope.$broadcast("callMainFunction", someData);
}

Then in the receiving controller, listen for the event. Also, don't forget to kill the listener when the controller gets unloaded

//handle SendDown event
var myListener = $scope.$on("callMainFunction", function (evt, data) {
    $scope.theMainFunction(data)
});

$scope.$on('$destroy', myListener);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda