Multiple controllers in $routeProvider

1,534 views
Skip to first unread message

Michael Bielski

unread,
Sep 13, 2012, 1:24:49 PM9/13/12
to ang...@googlegroups.com
If I have this app defined:

angular.module("my-app", ["dateCleaner", "numberFormatter"]).
  config(["$routeProvider", function ($routeProvider) {
  $routeProvider.
 when("/pos/docs/", { templateUrl: "/pos/partials/pos-documents-partial.htm", controller: posdocumentController }).
 when("/pos/docs/:mode/", { templateUrl: "/pos/partials/pos-transaction-partial.htm", controller: posdocumentController }).
 when("/pos/docs/:mode/:sid", { templateUrl: "/pos/partials/pos-transaction-partial.htm", controller: posdocumentController }).
 when("/pos/register/", { templateUrl: "/pos/partials/pos-register-partial.htm", controller: posregisterController }).
 when("/pos/reports/", { templateUrl: "/pos/partials/pos-reports-partial.htm", controller: posreportsController });
  } ]);

Can I specify multiple controllers in each .when()? If yes, how would I do it? I've looked in the docs and searched the group archives but don't see anything addressing multiple controllers in this manner.

Michael Alan Dorman

unread,
Sep 13, 2012, 2:17:39 PM9/13/12
to ang...@googlegroups.com
Michael Bielski <michael...@yahoo.com> writes:
> Can I specify multiple controllers in each .when()? If yes, how would
> I do it? I've looked in the docs and searched the group archives but
> don't see anything addressing multiple controllers in this manner.

If you think about it, this doesn't make sense: what part of the HTML in
the template would each controller be given responsibility for?

If your template contains HTML that represent views for several
controllers, you need to indicate that with ng-controller attributes on
the HTML in question.

Mike.

Michael Bielski

unread,
Sep 13, 2012, 2:30:06 PM9/13/12
to ang...@googlegroups.com
That was my initial thought, but I needed to ask to make sure I was coming to the right conclusion. Thanks for confirming!
Reply all
Reply to author
Forward
0 new messages