AngularJS - How to get directions to the controller in another module

I have a question related to modules and routing in angularjs. The requirements are the definition of all routing configurations in a single module - this can be called ModuleRtr.

As soon as the route is launched, it should call the controller (for example, TestCtr). This controller is defined in another module - call him ModuleCtrl.

If I try to do this, I get an exception like:

"The argument is TestCtrnot a function, got undefined"

. The reason is that with an angular broadcast event, the $routeChangeSuccesslistener tries to access the controller ( TestCtr) as part of the current module - ModuleRtr. Since it does not exist, it throws an error.

If I just create a controller TestCtrin ModuleRtr(the same one that has a route in it) then everything works. But I do not want this, I want to have TestCtrin another module. I also do not want to determine the route in the module ModuleCtrl.

So, in a simpler way, my question is: is it possible that a route defined in one module ( ModuleRtr) calls a controller defined in another module ( ModuleCtrl)?

Something I forgot to mention ... I do not want to link these 2 modules in any way. This, of course, includes listing dependencies when creating a module. I already tried dynamic loading TestCtr- this did not solve the problem.

: 2 () . ... - - / , (, ). . ( , - ?). , ( ), . - , . , ...

!

+4
1

, :

angular.module('myApp.home',[]);
angular.module('myApp.routing',[]);
...modules here...
angular.module('myApp', [
  'myApp.home',
  'myApp.routing'
]);

, myApp.home, myApp, myApp.routing.

, .

+1

All Articles