I\'m wondering what the use cases are for these two methods of creating a controller:
Using ngController:
myApp.controller(\'myContr
There is a subtle difference between a normal controller ( one created using ng-controller or routes ) and a directive controller.
A Directive controller is allowed to inject $element
. Note that while currently you can inject $element
into a normal controller as well, its bad practice to do so.
The sole purpose of a directive controller is for directive to directive communication. A very good use case is show on the main page of AngularJS for tabs component.
A directive controller allows directives to have functions. Because these controller instances can be 'required' in other directives - other directives can communicate / operate on this directive using the controller instance.
The only reason to use a controller with a directive is if you want to do some kind of directive to directive communication. For anything else you should probably stick with writing all your scope
logic in the linking function.