0

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?
Community
  • 1
  • 1
alex
  • 6,818
  • 9
  • 52
  • 103

1 Answers1

0

Looks like the

function FooCtrl($scope, fooBar) {
    // $scope.foo = fooBar ...
});

function has been deprecated since the release of Angular 1.2.

alex
  • 6,818
  • 9
  • 52
  • 103