Questions tagged [rootscope]

Every AngularJS application has a single root scope. All other scopes are descendant scopes of the root scope. Scopes provide separation between the model and the view, via a mechanism for watching the model for changes. They also provide an event emission/broadcast and subscription facility.

Every part of an AngularJS application has a scope. At the ng-app level, this scope is called the $rootScope. When Angular starts to run and generate the view, it creates a binding from the root ng-app element to the $rootScope. This $rootScope is the eventual parent of all $scope objects. So we can say that the $rootScope object is the closest object we have to the global context in an Angular app.

$rootScope is deprecated. Using it will make migration to Angular 2+ more difficult.

Resources

176 questions
0
votes
3 answers

AngularJS + Ionic - how to call method on the second controller from first controller with deffer promise?

I need to call method for initialization user setting values (which are set to rootscope) from second cotroller in method of the first controller. After the values are succesfully set to rootscope return premise and continue in executing of the…
redrom
  • 11,502
  • 31
  • 157
  • 264
0
votes
1 answer

Not reflect my changes in `$rootScope` in angularjs

I'm having trouble trying to reflect my changes in $rootScope. As I understand (please note that I'm very new to angular), $rootScope is visible across controllers. What I'm trying to do is to update a value in $rootScope and trying to read that…
sameera207
  • 16,547
  • 19
  • 87
  • 152
0
votes
1 answer

Angular $broadcast only updating after page refresh

Hi I have a problem in Angular where $scope.$broadcast is only updating a listening value once the page has been refreshed once: One controller: $rootScope.$broadcast('myVar', myValue); Listener: $scope.$on('myVar', function(event, myValue) { …
rjmacarthy
  • 2,164
  • 1
  • 13
  • 22
0
votes
1 answer

Angular root scope and scope issues

I have noticed that in one of my controllers I am getting $rootScope and $scope injected, and they both point to the same object. Furthermore, in all my other controllers, the $scope object is shared. So whenever I inject scope, it contains the…
lintmouse
  • 5,079
  • 8
  • 38
  • 54
0
votes
2 answers

AngularJS - How do I modify variables in $rootScope?

I've got a potentially really dumb question, but how do I modify variables up in $rootScope in Angular? I've got a slide-in sidebar that I want to change the content on whenever someone clicks on a thumbnail, and I figured the easiest way to handle…
sarsparillo
  • 53
  • 1
  • 10
0
votes
1 answer

how to use angular services to run a function and assign result to $rootScope

For some reason I have a problem wrapping my head around Angular logic, but I am determined to understand this. I am trying to run a function at application start that loops through an object and stores the result globaly. I am trying to do this…
Jason Spick
  • 6,028
  • 13
  • 40
  • 59
0
votes
1 answer

update $rootScope.$broadcast

How can I update $rootScope.$broadcast with new value? Consider this code: var test = "fisk"; if(angular.element(this).hasClass('monster')) { var monster_info = angular.element(this).find("img").attr("title"); $http.get("lib/terrain.php",…
user500468
  • 1,183
  • 6
  • 21
  • 36
0
votes
1 answer

$rootScope not changing content.... What is my error?

I am having problem with $rootScope. I am changing the value in "button" clicked event, but it's NOT changing in the directive. HTML page shows "TEST" to start with, on button click, I am expecting to change to "CLICKED". What is the mistake? in my…
0
votes
2 answers

$scope cannot set property on $stateChangeStart

Hi I'm new to angularjs and I'm using $rootScope to change a $scope variable on $stateChangeSuccess. The problem is, i get an error message that says, "TypeError: Cannot set property 'show' of null". This is a snipet of my code // unhide this…
Justin Case
  • 787
  • 2
  • 15
  • 30
0
votes
0 answers

AngularJS $route and $rootScope not being objects

It appears that $rootScope and $route change. I don't know how to really explain it, but hopefully the following code will clear things up. Any advice on why this happens or how I can go about fixing it would be very helpful. Controller…
robert
  • 819
  • 1
  • 10
  • 24
0
votes
2 answers

Angular Directive that Toggles Visibility of Elements

I've build a directive that change the $rootScope.showContent value to true or false. Then i use ng-show="showContent" in order to Hide or Show elements. This approach works fine but i want to avoid using $rootScope and also the use of scope.apply()…
Ricky Stam
  • 2,116
  • 21
  • 25
0
votes
2 answers

Unexpected behavior for $interval in .run block

I have an Angular JS application and I want to do a global action every second when the route changes successfully. So I created a .run() block in which I DI $interval and use the $interval on $routeChangeSuccess. The strange thing is that after…
Cristi Berceanu
  • 1,693
  • 1
  • 10
  • 12
0
votes
2 answers

AngularJS $rootScope variable exists, but not accessible

I set a $rootScope variable in one of my modules and now want to access that same $rootScope variable in another module. Thus far I can see that in both modules the variable has been set properly, but when I try accessing the variable in $rootScope,…
Shawn Taylor
  • 1,434
  • 5
  • 26
  • 36
0
votes
1 answer

Setting $rootScope & changing its value

I want so set a $rootScope variable stateSelection value default as false. So when my applciation runs the value of the $rootScope.stateSelection will be false. I want to know how to set it at the time of initialization of app. Right now i am…
Anup
  • 9,396
  • 16
  • 74
  • 138
0
votes
4 answers

Use $rootScope to returns json in AngularJS ?

I have this function which returns json with $scope.product_owners = data $http({ url: "php/functions.php", method: "GET", params: { action: "get_product_owners" } }).success(function(data) { $scope.product_owners =…
Steffi
  • 6,835
  • 25
  • 78
  • 123
1 2 3
11
12