How AngularJS prefixes $ and $$ are used? Last Updated : 31 Jul, 2020 Comments Improve Suggest changes 1 Likes Like Report $: The $ in AngularJs is a built-in object.It contains application data and methods. The scope($) acts as a link between controller and view. Scope($) Inside the controller function the properties and the methods to the scope($) can be attached. Expression, ng-model, or ng-bind directive can be used to display the scope data in the view. html <!DOCTYPE html> <html> <head> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular.min.js"> </script> </head> <body ng-app="Ng"> <h1>$scope</h1> <div ng-controller="myController"> Message: <br /> {{message}}<br /> <span ng-bind="message"></span> <br /> <input type="text" ng-model="message" /> </div> <script> var ngApp = angular.module('Ng', []); ngApp.controller('myController', function ($scope) { $scope.message = "GFG!"; }); </script> </body> </html> Output: Example 2: html <!DOCTYPE html> <html> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"> </script> <body> <div ng-app="myApp" ng-controller="myCtrl"> First Name: <input type="text" ng-model="firstName" /><br /> Middle Name: <input type="text" ng-model="middleName" /><br /> Last Name: <input type="text" ng-model="lastName" /><br /> <br /> Full Name: {{firstName +middleName+ " " + lastName}} </div> <script> var app = angular.module("myApp", []); app.controller("myCtrl", function ($scope) { $scope.firstName = "Geeks"; $scope.middleName = "for"; $scope.lastName = "Geeks"; }); </script> </body> </html> Output: $rootScope: The AngularJS application consists of a single $rootScope. All the other $scope are child objects.$rootscope has properties and methods attached to it which will be available be to all the controllers. MethodDescription $newIt is used to create new Child Scope$watchIt is used to Register a callback which is to be executed whenever the model property changes.$watchGroup It is used to register a callback which is to be executed whenever model properties changes. We specify an array of properties in this. $watchCollectionIt is used to register a callback which is to be executed whenever model object or array property changes.$digestIt processes all of the watchers of the current scope and its children.$destroyRemove the current scope from parent scope.$evalExecute expressions on the current scope.$emitIt is used to dispatch the specified event upwards till $rootScope.$broadcastIt is used to dispatch the specified event downwards till child Scope. Example 3: html <!DOCTYPE html> <html> <head> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular.min.js"> </script> </head> <body ng-app="Ng"> <h1> $watch </h1> <div ng-controller="Controller"> Enter Message: <input type="text" ng-model="message" /> <br /> New : {{newMessage}} <br /> Old : {{oldMessage}} </div> <script> var ngApp = angular.module('Ng', []); ngApp.controller('Controller', function ($scope) { $scope.message = "GFG!"; $scope.$watch('message', function (newValue, oldValue) { $scope.newMessage = newValue; $scope.oldMessage = oldValue; }); }); </script> </body> </html> Output: $$ $$ in this are treated as private variables. We use $$ to avoid the internal variable conflicts and not to expose for external use. Some of them are listed below:- $$observers, $$watchers, $$childHead, $$childTail, $$ChildScope etc. Method Description $$watchersIt contains all of the watches associated with the scope$$asyncQueueIt is a async task queue.It is consumed on every digest$$postDigest(fn)It executes fn after the next digest cycle.$$destroyedIt destroys the scope. Syntax: $$('.selector'); or element.all(by.css('.selector')); A common ways of communication between modules of application, with the help of core AngularJS functionality is establishing a connection between controllers using $parent, $$childHead, $$nextSibling. Example: html <!DOCTYPE html> <html> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"> </script> <body> <div ng-app="myApp" ng-controller="myCtrl"> First Name: <input type="text" ng-model="firstName" /><br /> Middle Name: <input type="text" ng-model="middleName" /><br /> Last Name: <input type="text" ng-model="lastName" /><br /> <br /> Full Name: {{firstName +middleName+ " " + lastName}} </div> <script> var app = angular.module("myApp", []); app.controller("myCtrl", function ($scope) { $$scope.firstName = "Geeks"; $$scope.middleName = "for"; $$scope.lastName = "Geeks"; }); </script> </body> </html> Output: The above output will be produced when we add $$, since, it acts as private object. So, to prevent accidental name collisions while writing your code angular prefixes public objects with $ and private objects with $$. Create Quiz Comment S sharmaanushka Follow 1 Improve S sharmaanushka Follow 1 Improve Article Tags : Web Technologies AngularJS AngularJS-Misc Explore AngularJS BasicsAngularJS Tutorial 5 min read Introduction to AngularJS 4 min read Angular CLI | Angular Project Setup 3 min read AngularJS Expressions 2 min read AngularJS Modules 3 min read AngularJS ng-model Directive 4 min read AngularJS Data Binding 4 min read AngularJS Controllers 3 min read AngularJS | Scope 2 min read AngularJS Services 4 min read AngularJS | AJAX - $http 3 min read AngularJS | Tables 2 min read AngularJS Select Boxes 2 min read AngularJS SQL 3 min read AngularJS HTML DOM 2 min read AngularJS Events 3 min read AngularJS | Forms 3 min read AngularJS Form Validation 3 min read AngularJS | API 2 min read AngularJS and W3.CSS 2 min read AngularJS Includes 3 min read AngularJS Animations 1 min read AngularJS | Application 3 min read AngularJS DirectivesAngularJS Directives 9 min read AngularJS ng-app Directive 1 min read AngularJS ng-bind Directive 2 min read AngularJS ng-bind-html Directive 2 min read AngularJS ng-bind-template Directive 2 min read AngularJS ng-blur Directive 1 min read AngularJS ng-change Directive 2 min read AngularJS ng-checked Directive 2 min read AngularJS ng-class Directive 2 min read AngularJS ng-class-even Directive 2 min read AngularJS ng-class-odd Directive 2 min read AngularJS ng-click Directive 2 min read AngularJS ng-cloak Directive 2 min read AngularJS ng-controller Directive 2 min read AngularJS Directives Complete Reference 2 min read AngularJS FiltersAngularJS | Filters 7 min read AngularJS currency Filter 2 min read AngularJS | date Filter 2 min read AngularJS filter Filter 3 min read AngularJS json Filter 2 min read AngularJS limitTo Filter 2 min read AngularJS lowercase Filter 1 min read AngularJS number Filter 1 min read AngularJS orderBy Filter 4 min read AngularJs uppercase Filter 1 min read AngularJS Converting FunctionsAngularJS angular.lowercase() Function 2 min read AngularJS angular.uppercase() Function 1 min read AngularJS angular.forEach() Function 1 min read AngularJS Comparing FunctionsAngularJS angular.isArray() Function 2 min read AngularJS angular.isDate() Function 2 min read AngularJS angular.isDefined() Function 2 min read AngularJS angular.isElement() Function 2 min read AngularJS angular.isFunction() Function 2 min read AngularJS angular.isNumber() Function 2 min read AngularJS angular.isObject() Function 2 min read AngularJS | angular.isString() Function 1 min read AngularJS angular.isUndefined() Function 2 min read AngularJS angular.equals() Function 2 min read AngularJS angular.toJson() Function 2 min read AngularJS QuestionsHow to bundle an Angular app for production? 4 min read How to add many functions in one ng-click directive? 2 min read How to directly update a field by using ng-click in AngularJS ? 3 min read How to Add Dynamic Options for Multiple Selects Inside ng-repeat Directive ? 3 min read How to detect when an @Input() value changes in Angular? 3 min read How to open popup using Angular and Bootstrap ? 2 min read How to reload or re-render the entire page using AngularJS? 2 min read How to add input fields dynamically on button click in AngularJS ? 2 min read How to Create Button Dynamically with Click Event in Angular ? 2 min read How to use jQuery in Angular ? 2 min read AngularJS Examples 2 min read Like