Live data from Hacker News

Mistakes AngularJS Developers Make

airpair.com

71–74 of 74 posts

Re: Mistakes AngularJS Developers Make

#71
post #9

Point 3 about "Dependency injection" is often not needed. Just use ng-annotate before minify/uglify, and it will convert the code to the array syntax for you. It handles most of the cases, leaving your code without the ugly array stuff. It doesn't work for everything, though, so suddenly it blows up. So if you want to be 100% sure your code works as intended do it manually.

It sounds like you talked yourself into doing it the way the author in the article suggests halfway through your post :)

Well, yeah, deployed a minified angular app yesterday, and ng-annotate handled almost everything except a controller that's initialized a custom way. So it broke. :(

Re: Mistakes AngularJS Developers Make

#73
post #71

Earlier quoted context omitted.

It sounds like you talked yourself into doing it the way the author in the article suggests halfway through your post :)

Well, yeah, deployed a minified angular app yesterday, and ng-annotate handled almost everything except a controller that's initialized a custom way. So it broke. :(

That occasionally happens when you do things in non-standard ways, although ng-annotate has become quite smart lately and can now follow references and more. Did you use the latest version (also feel free to open an issue)? ng-strict-di in AngularJS 1.3 will greatly improve the error messages for these situations.

Re: Mistakes AngularJS Developers Make

#74
post #33
post #9

Point 3 about "Dependency injection" is often not needed. Just use ng-annotate before minify/uglify, and it will convert the code to the array syntax for you. It handles most of the cases, leaving your code without the ugly array stuff. It doesn't work for everything, though, so suddenly it blows up. So if you want to be 100% sure your code works as intended do it manually.

ng-annotate works just fine with regular angular controllers/filters/providers/services/etc. definitions, but I would not trust it for special injections found in such stuff such as $state definitions with resolves and maybe $get with the factory returned by a provider.

it can certainly not support everything, partly because of limitations imposed by static analysis, buy you may be surprised with what it can handle.

Also: For situations where you don't know whether ng-annotate will detect a form or not (assuming you already use ng-annotate for your project), you can use explicitly use /* @ngInject */ or ngInject() to avoid stuttering the array yourself.

Post reply on HN