SlideShare a Scribd company logo
What is $rootScope in
AngularJs
 $rootScope is a parent scope of all $scope and can be sharedtoall $scope.
 One applicationcanhave onlyone $rootScope.
 $scope is a JavaScriptobjectassociatedtocontroller but$rootScope isnot.
 Scopesprovide separationbetweenmodel andthe view.
 For use of $rootScope needtoinjectintocontroller.
 Methodsand properties createdinthe $scope objectare onlyaccessed insidesame controllerin
view.
 All otherscopesare descendantscopesof the rootscope.
<!DOCTYPE html>
<html>
<head>
<title>Share data between controllers in AngularJs with $rootScope</title>
<link rel="stylesheet"
href="http://getbootstrap.com/2.3.2/assets/css/bootstrap.css">
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.4/angular.js"></scri
pt>
<script>
var app = angular.module("myApp", []);
app.run(function($rootScope) {
$rootScope.userData = {};
$rootScope.userData.firstName = "Ravi";
$rootScope.userData.lastName = "Sharma";
});
app.controller("firstController", function($scope, $rootScope) {});
app.controller("secondController", function($scope, $rootScope) {});
</script>
</head>
<body ng-app="myApp">
<div ng-controller="firstController">
<br>
<input type="text" ng-model="userData.firstName">
<br>
<input type="text" ng-model="userData.lastName">
<br>
<br>First Name: <strong>{{userData.firstName}}</strong>
<br>Last Name : <strong>{{userData.lastName}}</strong> </div>
<hr>
<div ng-controller="secondController"> Showing first name and last name on
second controller: <b>
{{userData.firstName}} {{userData.lastName}}</b> </div>
</body>
</html>
Thanks
www.codeandyou.com
http://www.codeandyou.com/2015/09/what-is-
rootscope-in-angularjs.html
Keywords - What is $rootScope in AngularJs, $rootScope, AngularJs
$rootScope

More Related Content

DOCX
Understanding angular js $rootscope and $scope
DOCX
Directives
DOCX
Shaping up with angular JS
DOCX
Controller in AngularJS
PDF
Activity
PPTX
AngularJS Introduction
PPTX
React django
PDF
Spice up your projects with google apps (1)
Understanding angular js $rootscope and $scope
Directives
Shaping up with angular JS
Controller in AngularJS
Activity
AngularJS Introduction
React django
Spice up your projects with google apps (1)

What's hot (18)

PDF
Discover AngularJS
PDF
Deep dive into AngularJs for Beginners
PPTX
Angular - Beginner
DOCX
Filters in AngularJS
DOCX
Different way to share data between controllers in angular js
PDF
Components in AngularJS and React
PDF
Simple restfull app_s
PDF
AngularJS best-practices
PPTX
Angular js PPT
PDF
Advanced Tips & Tricks for using Angular JS
PDF
Angular Best Practices v2
PPTX
Angular js
PDF
Angular js
PDF
Patterns Are Good For Managers
PDF
Introduction to AngularJS
PDF
Getting Started With Android Library Projects
PDF
Angular js
PDF
One Weekend With AngularJS
Discover AngularJS
Deep dive into AngularJs for Beginners
Angular - Beginner
Filters in AngularJS
Different way to share data between controllers in angular js
Components in AngularJS and React
Simple restfull app_s
AngularJS best-practices
Angular js PPT
Advanced Tips & Tricks for using Angular JS
Angular Best Practices v2
Angular js
Angular js
Patterns Are Good For Managers
Introduction to AngularJS
Getting Started With Android Library Projects
Angular js
One Weekend With AngularJS
Ad

Similar to What is $root scope in angularjs (20)

DOCX
Sharing Data between controllers in different ways.
PPTX
Starting with angular js
PPTX
intro to Angular js
PPTX
Custom directive and scopes
PPTX
SPTechCon Boston 2015 - Whither SPServices?
PPTX
Training On Angular Js
PPTX
ASP.NET MVC, AngularJS CRUD for Azerbaijan Technical University
PDF
Modular Test-driven SPAs with Spring and AngularJS
PDF
AngularJS Basic Training
PPTX
Angular js
PPTX
Basics of AngularJS
PDF
Fragments: Why, How, What For?
PDF
JavaDo#09 Spring boot入門ハンズオン
PDF
Modern JavaScript, without giving up on Rails
PPTX
AngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
PPTX
Angular tutorial
PPT
AngularJS Mobile Warsaw 20-10-2014
PPTX
JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...
PPSX
PPTX
Building a dashboard using AngularJS
Sharing Data between controllers in different ways.
Starting with angular js
intro to Angular js
Custom directive and scopes
SPTechCon Boston 2015 - Whither SPServices?
Training On Angular Js
ASP.NET MVC, AngularJS CRUD for Azerbaijan Technical University
Modular Test-driven SPAs with Spring and AngularJS
AngularJS Basic Training
Angular js
Basics of AngularJS
Fragments: Why, How, What For?
JavaDo#09 Spring boot入門ハンズオン
Modern JavaScript, without giving up on Rails
AngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
Angular tutorial
AngularJS Mobile Warsaw 20-10-2014
JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...
Building a dashboard using AngularJS
Ad

More from codeandyou forums (16)

DOCX
How to validate server certificate
DOCX
How to call $scope function from console
DOCX
Understand components in Angular 2
DOCX
Understand routing in angular 2
DOCX
How to setup ionic 2
DOCX
MongoDB 3.2.0 Released
DOCX
Welcome to ionic 2
DOCX
What is JSON? Why use JSON? JSON Types? JSON Helpful Tools?
DOCX
How to install ssl certificate from .pem
DOCX
Protractor end-to-end testing framework for angular js
DOCX
How routing works in angular js
DOCX
How to use proxy server in .net application
DOCX
How to catch query string in angular js
DOCX
Angular.js interview questions
DOCX
How to set up a proxy server on windows
DOCX
How to save log4net into database
How to validate server certificate
How to call $scope function from console
Understand components in Angular 2
Understand routing in angular 2
How to setup ionic 2
MongoDB 3.2.0 Released
Welcome to ionic 2
What is JSON? Why use JSON? JSON Types? JSON Helpful Tools?
How to install ssl certificate from .pem
Protractor end-to-end testing framework for angular js
How routing works in angular js
How to use proxy server in .net application
How to catch query string in angular js
Angular.js interview questions
How to set up a proxy server on windows
How to save log4net into database

Recently uploaded (20)

PPTX
MYSQL Presentation for SQL database connectivity
PDF
Electronic commerce courselecture one. Pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Machine learning based COVID-19 study performance prediction
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
cuic standard and advanced reporting.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Encapsulation theory and applications.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
MYSQL Presentation for SQL database connectivity
Electronic commerce courselecture one. Pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
The AUB Centre for AI in Media Proposal.docx
Spectral efficient network and resource selection model in 5G networks
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
NewMind AI Weekly Chronicles - August'25 Week I
Unlocking AI with Model Context Protocol (MCP)
Advanced methodologies resolving dimensionality complications for autism neur...
Machine learning based COVID-19 study performance prediction
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Spectroscopy.pptx food analysis technology
cuic standard and advanced reporting.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Network Security Unit 5.pdf for BCA BBA.
Reach Out and Touch Someone: Haptics and Empathic Computing
“AI and Expert System Decision Support & Business Intelligence Systems”
Encapsulation theory and applications.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation

What is $root scope in angularjs

  • 1. What is $rootScope in AngularJs
  • 2.  $rootScope is a parent scope of all $scope and can be sharedtoall $scope.  One applicationcanhave onlyone $rootScope.  $scope is a JavaScriptobjectassociatedtocontroller but$rootScope isnot.  Scopesprovide separationbetweenmodel andthe view.  For use of $rootScope needtoinjectintocontroller.  Methodsand properties createdinthe $scope objectare onlyaccessed insidesame controllerin view.  All otherscopesare descendantscopesof the rootscope.
  • 3. <!DOCTYPE html> <html> <head> <title>Share data between controllers in AngularJs with $rootScope</title> <link rel="stylesheet" href="http://getbootstrap.com/2.3.2/assets/css/bootstrap.css"> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.4/angular.js"></scri pt> <script> var app = angular.module("myApp", []); app.run(function($rootScope) { $rootScope.userData = {}; $rootScope.userData.firstName = "Ravi"; $rootScope.userData.lastName = "Sharma"; }); app.controller("firstController", function($scope, $rootScope) {}); app.controller("secondController", function($scope, $rootScope) {}); </script> </head> <body ng-app="myApp"> <div ng-controller="firstController"> <br> <input type="text" ng-model="userData.firstName"> <br> <input type="text" ng-model="userData.lastName"> <br> <br>First Name: <strong>{{userData.firstName}}</strong> <br>Last Name : <strong>{{userData.lastName}}</strong> </div> <hr> <div ng-controller="secondController"> Showing first name and last name on second controller: <b> {{userData.firstName}} {{userData.lastName}}</b> </div> </body> </html>