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 ...

Get Rails, Angular, Postgres, and Bootstrap now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.