0

As title, I'd like to use more than one controller inside some sub-view

routes.js (eg.):

.state("multi",{
            url: "/multi",
            views: {
                "": {
                    templateUrl: "multipleView.htm",
                    controller: "MainCTRL",
                    controllerAs: "ctrl"
                },
                "viewA@multi": {
                    templateUrl: "testingBlock.htm",
                    controller: ["CtrlOne", "CtrlTwo"],
                    controllerAs: "ctrl"
                },
            });

Or should I put CtrlOne and CtrlTwo inside a third controller:

function CtrlThree($scope){
         CtrlOne($scope);
         CtrlOTwo($scope);
}
Donovant
  • 3,091
  • 8
  • 40
  • 68
  • A couple things. Firstly, naming every `controllerAs` the same is a recipe for disaster. Secondly, your premise here seems flawed. A controller's *only* purpose is to be the glue for a view, so having more than one controller for one view seems wrong. What is it you are really trying to accomplish with this? – Claies Jul 17 '15 at 16:30

1 Answers1

4

Why not put the controller in the view instead of specifying it on the routeProvider.

Also do the controllers have a hierarchy or do you want them to all just work on the same level.

Example of what I mentioned above.

<div ng-controller="CtrlOne"> <div ng-controller="CtrlTwo"></div> </div>

This would be the html inside the "multipleView.htm" file.

Phil Kearney
  • 166
  • 8