Why do some variables start with a dollar sign?

4,677 views
Skip to first unread message

John Wheeler

unread,
Mar 25, 2013, 6:21:41 PM3/25/13
to ang...@googlegroups.com
It didn't really catch my attention while using $scope and $rootScope, but after using formcontroller and seeing the $dirty, $pristine, and all that, I have to ask. What is the convention going on in angular when prefixing certain things with a dollar sign? Is that so they don't get mixed up with client code?

Thanks,
John

Antonello Pasella

unread,
Mar 26, 2013, 5:11:54 AM3/26/13
to ang...@googlegroups.com
http://docs.angularjs.org/guide/dev_guide.services.understanding_services

"Like other core Angular variables and identifiers, the built-in services always start with $ (such as $http mentioned above)."

Michael Glass

unread,
Jun 18, 2013, 5:31:13 PM6/18/13
to ang...@googlegroups.com
Angular's toJson and equals ignore $ prefixed vars.  Is it ok for me to use $ to set pseudo-private params on objects?  Should I consistently use $$ instead of $?

Matthieu Larcher

unread,
Jun 19, 2013, 4:28:05 PM6/19/13
to ang...@googlegroups.com
Angular prefixes its exposed variables with a $, and its internal variables with $$, so you shouldn't use either one for your code.
Reply all
Reply to author
Forward
0 new messages