0

When looking at examples of an Angular controller I have seen this (named function):

function GreetingController($scope) {
  $scope.greeting = 'Hola!';
}

And this (anonymous function):

var GreetingController = function ($scope) {
  $scope.greeting = 'Hola!';
}

Is there any real difference in this syntax when using these from Angular?

DeborahK
  • 47,261
  • 9
  • 85
  • 112
  • See: http://stackoverflow.com/questions/336859/var-functionname-function-vs-function-functionname – hugomg Jun 10 '14 at 23:13

1 Answers1

0

With regards to angular, no. However I would only define controllers in this fashion for very simple apps, or demos. You should really be modularising your project. For example:

angular.module('myapp', ['ngRoute', 'ngResource', ... more dependencies])
    .config(['$locationProvider', '$routeProvider',     
    function($locationProvider, $routeProvider) {
        // app config here
    }])
    .controller(['$scope',
    function($scope){
        // controller code here
    }]);    
Matt Way
  • 28,863
  • 10
  • 70
  • 79