What Is the $$ (Double Dollar Sign) Used for in Angular

What is the $$ (double dollar sign) used for in angular?

  • Single $ for reserved, public identifiers
  • Double $$ for reserved private identifiers

To quote the docs:

$ Prefix Naming Convention

...

If you inspect a Scope, you may also notice some properties that begin with $$. These properties are considered private, and should not be accessed or modified.

angular2 style guide - property with dollar sign?

$ suffix (popularized by Cycle.js) is used to indicate that the variable is an Observable.
It could make it to the official style guide too but it's not there yet

Read more here : What does the suffixed dollar sign $ mean?

Update:
Read more about the trailing “$” sign on Angular website here:
https://angular.io/guide/rx-library#naming-conventions-for-observables

what is $$ before varible in typescript?

$ and also $$ are valid variable names in javascript with no special meaning whatsoever and thus also have no special meaning in typescript.

What does $ sign at the end of function name indicate?

Syntactically, the dollar ($) character has no special meaning in JavaScript identifiers.

It is, however, sometimes used by convention to indicate that a variable holds an Observable or that a function will return an Observable.

Meaning of $$ in angular

$$ prefix variable are treated as private variable, the reason behind adding $$ before the variable name is, that will avoid the internal variable conflicts and they wouldn't be exposed for external use.

Like in angular you could find many of them, $$observers, $$watchers, $$childHead, $$childTail, $$ChildScope, etc.

AngularJS and its use of Dollar Variables

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.

    <div ng-init="n = { visible: 'foo', $ignore: 'bar' };">{{ n }}</div>
  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 $.

What does ${} (dollar sign and curly braces) mean in a string in JavaScript?

You're talking about template literals.

They allow for both multiline strings and string interpolation.

Multiline strings:

console.log(`foobar`);// foo// bar


Related Topics



Leave a reply



Submit