In AngularJS, why should I use a $ at the beginning of a scope object name? -


no js experience. learning angularjs

so i've read https://docs.angularjs.org/guide/scope, , i've looked @ stackoverflow.com answers on $ used in javascript. understand $ has specific use in libraries, jquery, , in newer versions of javascript seen standard character variable names. question is...

why common in angularjs see scope object $ in front of though $ isn't necessary?

an example of angularjs scope object without using $

scope object without $

app.controller('maincontroller', ['$scope', function(withoutdollarsign){     withoutdollarsign.title = 'string here'; }]); 

or scope object $

app.controller('maincontroller', ['$scope', function($withdollarsign){     $withdollarsign.title = 'string here'; }]); 

the angular api documentation states:

angular prefixes $ , $$: prevent accidental name collisions code, angular prefixes names of public objects $ , names of private objects $$. please not use $ or $$ prefix in code.

in code snippet, showing 1 method dealing dependency injection. in method, array of arguments passed, , array matched, in order, parameters passed in function. customary, not mandatory, use same name array value value being passed function. using different names can create confusion in code, looking @ code later, might not understand @ first glance withoutdollarsign $scope.

in practice, $ or $$ used developer identify objects created framework, vs. objects created in own code. there no special significance in javascript language usage, convention used angular contributors.

as stated here, it's recommended not use $ or $$ in own code when interacting angular framework.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -