specifying AngularJS controller: benefits using ngController vs. $routeProvider

angularjs, angularjs-controller, angularjs-routing

Solution

If you think of a view including all scripts as a self-contained package, developed by a single person or team, then `ngController` is the way to go, imho.

`$routeProvider` on the other hand provides you with advanced features like injection of values via the `resolve` property of the route. That way you can have your AJAX loaded data directly injected into your controller, e.g., instead of the controller having it to get itself. Or have the route change to wait for that data etc.

Btw: If you need routing and nested views you can take a look at angular ui-router

Problem

There are two ways (AFAIK) to associate a controller with a view template/partial: the route specified in `$routeProvider` and the `ngController` directive. Especially (but not exclusively) for simple routing, is there any benefit/efficiency of one over the other? My project currently uses the $routeProvider approach, but I've been given the task of nesting views. This seems simple enough with ngInclude, as long as the partial specifies its ngController.

Original source