O'Reilly logo

Rails, Angular, Postgres, and Bootstrap by David B. Copeland

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Nesting Controllers to Organize Code

So far, we’ve had a setup of one controller per view. We could continue doing that here, and add the necessary code to CustomerDetailController to get the user’s credit card info from the second source. Although for the task at hand it might not be too complex to do so, you should learn how to do this a better way, especially if things get complex later. It’s not much more code, and will make our Angular app easier to work.

We can achieve this separation by using a second, nested controller, attached to a subset of our view using ng-controller. We didn’t need to use ng-controller after we introduced angular-route, because the controller to use is configured in the routing configuration. But we can still ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required