- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2017 12:41 AM
May i know what is difference between scope and rootscope.
How do we decide which one to use?
Solved! Go to Solution.
- Labels:
-
Service Portal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2017 02:09 AM
$scope: It is like a local variable and it can be accessible only within the component eg. controller,service
when we want any variable to be used within the class or component or want without having a reference to the containing class anyone can access that element then we should use $scope as it would not allow this variable to be accessible from outside.
$rootscope: It is like the global variable and it can be accessible from everywhere.
a common property that can be shared with anyone no restrictions on accessibility. a shared resource which can be accessed from anywhere.
for more information refer the above link that i had shared

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2017 12:52 AM
Hi Amaneet,
Please check the link below.
javascript - Difference between $scope and $rootScope - Stack Overflow

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2017 02:09 AM
$scope: It is like a local variable and it can be accessible only within the component eg. controller,service
when we want any variable to be used within the class or component or want without having a reference to the containing class anyone can access that element then we should use $scope as it would not allow this variable to be accessible from outside.
$rootscope: It is like the global variable and it can be accessible from everywhere.
a common property that can be shared with anyone no restrictions on accessibility. a shared resource which can be accessed from anywhere.
for more information refer the above link that i had shared
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2017 02:22 AM
HI Amaneet,
In simpler words:
$scope: We can get ng-model properties in particular controller from the particular page by using this
$rootscope: We can get all ng-model properties in any controller from any page by using this.
consider one scenario . you have one main page and in that page you have different templates. every templates has their own controller. There is one ID which you need in every controller. Fetch that ID from service in once controller n save it in $rootscope. so that it will accessible for every controller.
Please provide your feedback appropriately (Like, Helpful, Endorse AND/OR Correct) to help community.
Thank you!
Regards,
Jyoti