Name your Angular controller initialization functions so they appear in call stacks

So until yesterday I would create controllers like this:

angular.module('myApp', []).controller('DemoController', ['$scope', function($scope) {
    // awesome stuff here
}]);

However, in call stacks, the code executing inside the controller’s function just shows up as (anonymous method). If I actually name the function, then it shows up as that in the call stack. So now I write it this way:

angular.module('myApp', []).controller('DemoController', ['$scope', function DemoController($scope) {
    // awesome stuff here
}]);

This technique works for any anonymous function in JavaScript, not just for Angular app.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *