Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Link Function: $Scope vs Scope

In angular directives I've seen in tutorials either

 link: function($scope,$element,attrs)

or

 link: function(scope,element,attrs)

Now I know that the '$' means a service in angular , does this hold here ? What exactly is the difference between $scope and scope ? Same goes to element vs $element

like image 578
Joel Blum Avatar asked Sep 10 '13 12:09

Joel Blum


1 Answers

In your specific example, it does not matter what the parameters are named in your link function. When Angular processes the directive, it will pass the scope, element and attrs (and even a controller instance if configured) to your link function.

You could do this (not recommended):

link: function (s, e, a)

and it will work fine.

$ is the prefix used by Angular. It is a convention and helps avoid naming collisions.

like image 96
Mark Sherretta Avatar answered Sep 22 '22 22:09

Mark Sherretta