I've been looking at a lot of Angular tutorials online, and I'm seeing some inconsistencies in the way that AngularJS controllers are defined.
Most examples use a "chaining" syntax when instantiating controllers:
var myApp = angular.module('myApp', []).controller('FooCtrl', function() {
// $scope.foo = ...
});
// alternatively:
var myApp = angular.module('myApp', []);
myApp.controller = function($scope, fooBar) {
// $scope.foo = ...
}
In other examples I've seen, controllers are defined like you would define an ordinary Javascript function. I think I've encountered this approach in more than one tutorial!
var myApp = angular.module('myApp', []);
function FooCtrl($scope, fooBar) {
// $scope.foo = fooBar ...
});
- What's the difference between these two declarations?
- Is the second example simply deprecated?
- If not, then how does this Controller work with Angular's $digest cycle?