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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access