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
5
votes
1 answer

ngHide/ngShow using $rootScope in Single Page Application

Reaching out to you all for help yet again for AngularJS. I'm building a SPA where my Layout (master) Page is divided in to three section left navigation bar, center content, right item list bar. My right item list should be hidden when I load my…
Ajay Srikanth
  • 1,095
  • 4
  • 22
  • 43
5
votes
1 answer

$rootscope value undefined in Controller

I have a $rootscope object defined in the run like so.. //Start the AngularJS App var angularApp = angular.module('angularApp') //Run at the start of the Angular Application .run(function ($rootScope, $location, $firebase, $firebaseSimpleLogin) { …
Jason
  • 53
  • 1
  • 5
5
votes
4 answers

Angular js - cache a rootScope param and it's value

Hey how do i cache for x time this simple object that i set via $http ( $rootScope.config.app_genres)? $http.get($rootScope.config.app_ws+'get/genres',{},{cache:true}).success(function(response) { $rootScope.config.app_genres = response; …
itsme
  • 48,972
  • 96
  • 224
  • 345
5
votes
2 answers

Angular - can I $broadcast a message from outside an angular app?

I have a scenario where I need non-angular code (in this case Facebook and Twitter JS sdk's) to broadcast an event that angular controllers can listen to. Why? After the initial page load, I load and revise content in the page via AJAX. The content…
sa125
  • 28,121
  • 38
  • 111
  • 153
5
votes
2 answers

Why can't I use $rootScope instead of $scope?

HTML file is this : HTTP Request
exAres
  • 4,806
  • 16
  • 53
  • 95
4
votes
1 answer

$rootScope.$broadcast in factory cannot change a value in other $scope

I have a home template (ionic) has a tab like this:
Hugh Hou
  • 2,344
  • 5
  • 31
  • 55
4
votes
1 answer

Prevent $rootScope.$on from calling function several times

I have a $rootScope.$on code on top of a controller. I noticed that everytime I load/call this controller, the $rootScope.$on listener increases meaning it will add and add and add a listener, indefinitely as you visit the controller. I noticed it…
devwannabe
  • 3,160
  • 8
  • 42
  • 79
4
votes
1 answer

AngularJS Factory $rootScope.$on Cleanup

How do I cleanup $rootScope.$on event subscriptions from inside a service? I have a Factory that is being initialized in different controllers in my AngularJS application, where a $rootScope.$on event subscription is being declared. My problem is,…
4
votes
1 answer

Using $rootScope during protractor testing

I am trying to do an End2End test and I need to manipulate data from the Server (mocking it)...Is there a way to access $rootScope in Protractor so that I can tell the server (Node) what data I am looking for to complete a test? I would inject…
Serious
  • 153
  • 11
4
votes
1 answer

Why $routeChangeStart fires twice in AngularJS?

I have this function, when it's executed, it's fired twice. I see alert(ok) then alert(ok) I don't know why. $rootScope.$on( "$routeChangeStart", function(event, next, current) { if ( next.templateUrl == "partials/login.html" ) { alert(…
Steffi
  • 6,835
  • 25
  • 78
  • 123
4
votes
1 answer

Setting initial $rootScope defaults don't seem to work

I would like to have few global variables that are UI related (i.e. open menu state). I decided to put these in $rootScope so they're always accessible. This is the code I've written: (function (angular) { angular .module("App", []) …
Robert Koritnik
  • 103,639
  • 52
  • 277
  • 404
3
votes
1 answer

$rootscope.$emit / $broadcast wont pass parameter

Im having the following: $rootScope.$on('setmoney',function (thisdata) { console.log("setting money"); console.log("money is : " + thisdata); }); and this somewhere else: $rootScope.$broadcast('setmoney', {cash:…
maria
  • 207
  • 5
  • 22
  • 56
3
votes
2 answers

$rootScope changed doesn't reflect on template

I'm a newbie in angularjs. I'm trying to build a simple app which contain login page and dashbboard page. Now, I got a problem with updating html template when rootScope changed. Here is my component template :