0

I am using

$scope.$on('$routeChangeStart', function (event, toState, toParams, fromState, fromParams)     
{
//content
$log.log(toState);
}

to keep track of the routes i am navigating to. When i print "toState" it is giving me an object, as shown below.

{
$$route: Object
loadedTemplateUrl: "views/homepage.html"
locals: Object
params: Object
pathParams: Object
scope: ChildScope
__proto__: Object
}

Here i am not 100% sure about "$$" in '$$route'. Can some one please explain about the difference between $ and $$.

1

1 Answer 1

3

Perhaps we can add to the link that Jiří Pospíšil included:

Similar Link

Other than just being significant to Angularjs, the '$$' or '$' are just characters that are allowed in variable names. Angularjs uses both to identify significance for you and their own development team as stated in the 'similar link'.

You could name all of your variables in the same way; but to avoid naming collisions, stay away from this practice. Here are some examples if you did...

$$$$myVariableName; $myVariableName$; myVariableName; $$$$$$myVariableName$$$$$$$$

Here is a link to test out JS variable names if you wish:

Variable Name Validator

Here is a link to MDN as well that explains allowed characters:

MDN allowed characters link

and here is the text:

Variables

You use variables as symbolic names for values in your application. The names of variables, called identifiers, conform to certain rules. A JavaScript identifier must start with a letter, underscore (_), or dollar sign ($);

subsequent characters can also be digits (0-9). Because JavaScript is case sensitive, letters include the characters "A" through "Z" (uppercase) and the characters "a" through "z"(lowercase).

Starting with JavaScript 1.5, you can use ISO 8859-1 or Unicode letters such as å and ü in identifiers. You can also use the \uXXXX Unicode escape sequences as characters in ientifiers.

Some examples of legal names are Number_hits, temp99, and _name.

Angulajs includes quite a bit of information in each object; some of the items are for Angularjs, and some are for the developer, which means that some may not be editable, but all should be available for reference if that is what you were going to use it for.

However, in future releases any private identifiers may disappear as the Angularjs team expects the developer not to use the reserved / private names.

update: Peaking into some of these private identifiers may also open up someones understanding of Angularjs as well; under-the-hood so to speak.

In the case of the posted 'similar link' here is what Angularjs says:

$ Prefix Naming Convention You can create your own services, and in fact we will do exactly that in step 11. As a naming convention, Angular's built-in services, Scope methods and a few other Angular APIs have a $ prefix in front of the name.

The $ prefix is there to namespace Angular-provided services. To prevent collisions it's best to avoid naming your services and models anything that begins with a $.

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Might want to change that code block about variables to a quote instead.
Thanks for the quote change.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.