javascript - Why wouldn't you use explicit annotations when defining controllers in AngularJS? -


i new angularjs , learning 2 styles of writing controller functions. seems though reason not use explicit annotations save time, doesn't seem reason. , being able minify/obfuscate code seems requirement want keep in application.

also note not asking better or asking debate. asking reasons (or in situation) more beneficial not use explicit annotations.

example of i'm talking about:

module('myapp').controller('mycontroller', function($scope) {}); 

vs.

module('myapp').controller('mycontroller', ['$scope', function($scope) {}]); 

the inline array annotation workaround on javascript limitations allow angular code minified , not stop working. isn't great solution because if forces duplicate code. , know how bad duplicate code is. angular documentation acknowledges that:

when using type of annotation, take care keep annotation array in sync parameters in function declaration.

it's way easy add new dependency , forget add corresponding annotation. or reorder arguments , forget update list of annotations. trust me. been there, done that.

fortunately there tools developed smart people take burden off our shoulders taking care of annotating code automatically. known ng-annotate, mentioned @pankajparkar. have plug build process , code correctly annotated.

to honest, find odd angular documentation recommends against following approach.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -