Every 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. See the developer guide on scopes.
Questions tagged [angularjs-rootscope]
152 questions
1
vote
3 answers
Disable button in one controller from another
Consider I have two controllers Ctrl1 and Ctrl2. On clicking a button in Ctrl1, the button in Ctrl2 should be disabled.
Any sample code for this??

Akshara
- 127
- 1
- 2
- 12
1
vote
3 answers
AngularJS rootScope undefined in controller
I have a simple AngularJS app that has two template pages: login.html and content.html.
I use ng-view and routing to dynamically load those pages into the index.html.
That works fine.
Here is my index.html:

user3362334
- 1,980
- 3
- 26
- 58
1
vote
1 answer
Is setting the value of rootScope.angular a code smell?
I'm looking at this code that someone else wrote. This looks to me like a bad code smell. What could be a valid reason to copy a reference to angular under the $rootScope?
$rootScope._ = $window._;
$rootScope.angular = $window.angular;

Chris Halcrow
- 28,994
- 18
- 176
- 206
1
vote
1 answer
AngularJS: changing $rootScope variable doesn't change first selected option in ng-model
I have a specific problem which I can't seem to crack.
In html I have following code:
And in my…

svemiracBago
- 57
- 1
- 6
1
vote
1 answer
I need to access a variable in .run() module in angular and need to change the value of it in different controllers
.run(['$rootScope', '$state', 'Session', function ($rootScope, $state, Session) {
$rootScope.$on('$stateChangeStart', function (e, toState) {
console.log('inside .run')
if (toState.url == '/') {
e.preventDefault();
…

Ashik Jyothi
- 757
- 10
- 17
1
vote
1 answer
Angularjs variable out of ng-view
I want to have particular variable for menu to know which class to be active. Up to now I know how to set variable inside ng-view but I want to keep my menu out of that view. If I set variable in function in controller isn't visible outside of…

Sasa
- 553
- 7
- 25
1
vote
0 answers
How to avoid using $root on component's templates?
I'm trying to check if a user has a specific role from my component's template.
For example, this could be my session service :
function Session() {
'ngInject';
var userRoles = {};
...
function hasRole(role) {
…

redAce
- 1,558
- 4
- 14
- 24
1
vote
2 answers
angularjs change rootscope after promise in a controller
I'm trying to change some $rootscope variables from within a controller after a I have received a promise from a service.
The $rootscope variables are used to set the html page title attribute etc.
Below is the code I have, I created a function…

Holly
- 7,462
- 23
- 86
- 140
1
vote
2 answers
$rootScope.$broadcast usage in AngularJS
I am working with an app where I have the following line at the end of a service in service.js.
$rootScope.$broadcast('rootScope:Object')
Here Object is the output of an API service. If I now want to use this Object in my actual app.js file, how…

user168983
- 822
- 2
- 10
- 27
1
vote
0 answers
Does $routeOnChange placement matter for it to trigger?
Does it matter where we instantiate a $on listener with $routeOnChange? I currently have $rootScope.$on("$routeOnChange", myFunction) in two directives. In one directive the listener works fine when I refresh my website, but in the other directive,…

user6728767
- 1,123
- 3
- 15
- 31
1
vote
1 answer
$rootScope in AngularJS not working
I am new to AngularJS. I can successfully retrieve JSON data and display it on my html page with $scope (ASP.NET application). However, I am trying to store the data in $rootScope, so that I can access it in another controller, but it's not working.…

Johnathan
- 1,877
- 4
- 23
- 29
1
vote
1 answer
Angular $rootScope Behavior on Start and on Refresh
I have the following piece of code in Angular:
$rootScope.commands.forEach(function(element, index, array){
commands[element] = function() {alert(element + " Test Command!");}
});
It works when I log into the application for the…

MadPhysicist
- 5,401
- 11
- 42
- 107
1
vote
0 answers
Access $rootScope value in Kendo Grid for export to excel dynamic file name
This is HTML
------------
…

GOPAL SHARMA
- 657
- 2
- 12
- 37
1
vote
1 answer
custom $compile directive applies only sometimes in same scope
thanks for looking. I'll dive right in:
A JSON object has HTML links with ng-click attributes, employing ng-bind-html, with $sce's trustAsHtml to make the HTML safe. I have also used a custom angular-compile directive to compile the angular click…

lakewood
- 607
- 1
- 5
- 21
1
vote
3 answers
Unable to update the rootScope in angular
I am trying to send a request to a php file from one controller in angular and getting the response. I stored the response in a rootScope variable which is initialized in the controller.run() method with 0.
Now I am trying to use the updated…

Baradwaj Aryasomayajula
- 1,184
- 1
- 16
- 42