Ui-router for systems with many modules

Asked

Viewed 58 times

2

I came across a problem I have a Controller called Ordercontroller which is in two modules, Sales and Supply. When I route to the screen that will use this controller how can I define which of the two controllers I want to use, how can I define which module I want the controller from? I tried to register the route separately in each module, but still not the right one.

Complete code: https://plnkr.co/edit/iLUuUNKWZJhg23rrk1zB?p=preview

  • I think you should rename the controller, or it will use what was declared first.

  • @Celsomtrindade is correct. Use different names, or declare the controller only once.

  • then angular modules do not serve as a namespace or Packge of a "class"

  • @Ricardocarvalho no. Reference: http://stackoverflow.com/a/14909537/1845714

  • @I thank you for the reference. I’m sad, but if it’s the way, let’s do it like this :/

  • @Ricardocarvalho not so. It is certainly a limitation, but not very striking.

Show 1 more comment

1 answer

1

It would not be better if each module had its own controller, each with its own name and the logic that must be shared between the two controllers stay in a service?

Example:

angular
  .module('sales.module',[])
  .controller('SalesController',SalesController);

angular
  .module('suply.module',[])
  .controller('SuplyController',SuplyController);

angular
   .module('outro.module',[])
   .service('OrderService',OrderService)

Or you can put this logic into a parent controller and these other two inherit the parent controller.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.