I'm new to angular, every tutorial is doing things differently and it's confusing. I managed to understand best practices and follow them. But check this out:
-See how guys at Microsoft are putting $scope and function in dependency brackets.
On the other hand,this guy Egghead is doing this:
He is putting dependencies in function parameters.
Whats the difference and whats the best practice?
These effectively do the same thing and are different forms of Dependency Annotation provided by AngularJS. The latter will not work if the code is minified because it would become
.controller('TodoListController', function (a, b) {
and there is noa
service. The former still has the'$scope'
string, so Angular knows what service to inject.You can use the ng-annotate library to produce minification-proof code from implicitly annotated code.
I find implicit annotation easier to read and of course it is easier to write. If you need to minify your code, you can include a build with
ng-annotate
as an additional step anyway, so it shouldn't matter. If you don't need to minify your code and you're just writing non-production examples, there's no need to use inline array annotation anyway.This is unrelated, but injecting
$scope
is needed a lot less now because of Angular'scontroller as
syntax.