AngularJS and its use of Dollar Variables

ghz 1years ago ⋅ 3107 views

Question

Does anyone know if the reasoning behind the use of dollar methods and variables in angularJS is to instruct angularJS to avoid checking those values when a digestion is going on? So, if angular comes across $scope.$value and $scope.value, then it will avoid checking the former since it's prefixed with a dollar character in its variable name?


Answer

There are a few times Angular ignores variables prefixed with the dollar sign:

  1. In Schumli's comment below, where json filters will not output them

  2. When using the {{ }} directive, angular will not show nested $ variables. For example this only displays the visible property.

    {{ n }}
  3. Additionally when adding an explicit watcher on a scope object, changes to properties with a leading dollar sign of this object will not trigger the watcher. See this updated fiddle.

  4. angular.equals() ignores keys prefixed with $.