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
3
votes
2 answers

Angular JS how to pass value from rootscope into ng-model?

I have object into rootscope and i would like to display some values in form inputs. I tried following: But this is not working. How i should pass value…
redrom
  • 11,502
  • 31
  • 157
  • 264
3
votes
1 answer

AngularJS ui-router redirect after log in

I have a project using AngularJS with ui-router. Everything working fine beside the redirect from login screen to preview state on the first load. Default state is home - http://test/#/ For example, if user is not logged in -…
Valter
  • 2,859
  • 5
  • 30
  • 51
3
votes
2 answers

Angular.js - In controller wait until service returns value from server

In my Angular.js application I'm stucked with such problem. I have service which is called user and I call it on app.run to get user data from server like so: app.run(function (user, tracking) { user.initialize(); ... // some other code goes…
Kosmetika
  • 20,774
  • 37
  • 108
  • 172
3
votes
2 answers

AngularJS Data service vs $rootScope events

Can you please explain the use use of data services vs the use of $rootScope events. I have a list of say branches which provides edit functionality. On click of edit button I am broadcasting an event with root scope using…
Uday Sawant
  • 5,748
  • 3
  • 32
  • 45
3
votes
2 answers

how to access $rootscope variable in angularjs?

I want to assign some data to a global variable (may be $rootscope) which gets initialized at pageload. And then I want to access that data from all the controllers. How would I do that? // Edit : I tried following and it works as…
exAres
  • 4,806
  • 16
  • 53
  • 95
2
votes
5 answers

pass the value from one page to another using rootscope in angularJS

Login.js: app.controller('LoginFormController', ['$scope','$http','$rootScope', '$state', function($scope, $http, $rootScope, $state) { $scope.user = {}; $scope.authError = null; $scope.login = function() { $scope.authError =…
Abdul khader
  • 67
  • 13
2
votes
1 answer

$rootScope in onExit

I want to use $rootScope.$broadcast() inside onExit when state changes. But for this, I need to inject $rootScope in the .config(), which is not possible in angular onExit: function () { //onExit is executed when we leave that state…
Varun Sukheja
  • 6,170
  • 5
  • 51
  • 93
2
votes
0 answers

I am understanding rootScope and how it works.

I am understanding rootScope and how it works. While following a tutorial its been mentioned that a value mentioned on rootScope is available through entire application and if anything changes on rootScope it will reflect everywhere. In my code…
Megh
  • 145
  • 9
2
votes
2 answers

Angular: got undefined value when assign new variable with $rootScope variable

As mentioned on title, I have small issue to assign new variable with $rootScope variable. I have variable $rootScope.adulttotTicket with value 2. the value is int. So what I want is just to assign new variable newVal to $rootScope.adulttotTicket…
Fai Zal Dong
  • 323
  • 6
  • 25
2
votes
2 answers

What's the main difference between rootScope and scope in angularJs. How it internally works

I am new bee to angular js and I have been using $scope in my coding. However I understood like scope is to use for global variables to make sure I searched on angularJs docs but then found root scope details which are nt clear to me. Does anyone…
FayazMd
  • 386
  • 2
  • 22
2
votes
1 answer

use variable in both JQuery in an angularJS

I need to use an array that is being defined in a JQuery script inside of an angularJS controller script. I don't understand how $rootScope fits into this whole thing. Is this possible, Any advice? $(document).ready(function(){ …
2
votes
1 answer

Angular: attach $viewContentLoaded to manually bootstraped app

i have a angular module that i bootstrap manually.i am trying to get its $rootScope to attach a event listener for $viewContentLoaded. here is my code : angular.bootstrap(el, [appname]); //////////////////////////// Fixing…
Exlord
  • 5,009
  • 4
  • 31
  • 51
2
votes
0 answers

AngularJS: help me avoid this anti-pattern: setting variables on $rootScope before $location.path

Here's something simple and I think there must be a better way: I often need to navigate to a new view, and at the same time I want to provide some context information to the scope that will be created. I can't figure out how to do both simply --…
2
votes
1 answer

Call function from directive in $rootScope - AngularJS

What I want to do: I'm trying to create a function within a directive that can be called from the $rootScope. The Problem: It seems to only be working on the last item in the DOM which has this directive. I'm guessing that what's happening is…
mmm
  • 2,272
  • 3
  • 25
  • 41
2
votes
1 answer

Angularjs - Broadcast event is double fired

I have this simple code: //add new contact stuffs
// show the new contact when added
.controller('Contacts', function ($scope, contactsFactory)…
itsme
  • 48,972
  • 96
  • 224
  • 345
1 2
3
11 12