"Use scope instead of $scope in your link function"
victorb opened this issue · comments
"Use scope instead of $scope in your link function"
Why? What is the reason behind this?
Very often there is a misunderstanding of the meaning of scope
in the directive linking functions. Usually developers think that there is used dependency injection but that's not the case. Using scope
instead of $scope
is a way of making this clearer.
Also style guides are used for creating common practices - the same style is used in the AngularJS's source code.
Do you agree with this style guideline? Should I close the issue?
I tend to name parameters with a leading $ to show that they are jQLite/jQuery or some kind of ng-services.
I generally agree with this guideline. But I don't think a separation based on DI vs Non-DI is relevant here. The style guide recommends using Array-Syntax wherever DI is happening. This should already make it perfectly clear, that there is no DI going on in the link function.
However, using scope
instead of $scope
in the link function is the style chosen by AngularJS and used throughout it's source. It should therefore also go in the style-guide.
imho this issue can be closed.