Questions tagged [angularjs-rootscope]

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.

152 questions
32
votes
5 answers

Is binding objects to angular's $rootScope in a service bad?

In angular, I have an object that will be exposed across my application via a service. Some of the fields on that object are dynamic, and will be updated as normal by bindings in the controllers that use the service. But some of the fields are…
latentflip
  • 1,843
  • 3
  • 19
  • 22
8
votes
4 answers

AngularJS: $rootScope:infdig error when calling a ng-style function inside ng-repeat

I'm trying to build an animation on some phrases that will be displayed on the site main page, in a random position and with fade and translate effects. I would achieve this using ng-style attribute inside an ng-repeat attribute and setting the…
Androidian
  • 1,035
  • 1
  • 16
  • 40
8
votes
3 answers

How to reset $rootScope?

After user logs out, I need to clean up my $rootScope. I tried $rootScope.$destroy() but that didn't do the trick. Is there a way to loop through all the values in $rootScope and delete them or a method to simply reset it?
Adam Boostani
  • 5,999
  • 9
  • 38
  • 44
7
votes
3 answers

Best practice for using $rootscope in an Angularjs application?

We have a large Angularjs 1.6 application that has $rootscope scattered throughout the app in over 200 places in filters, services, routes, etc.. so it needs to be refactored, but I'm not sure how to know when to remove it. When is it a best…
James Drinkard
  • 15,342
  • 16
  • 114
  • 137
6
votes
1 answer

Angular: using $rootScope.$on vs $scope.$on to catch a $rootScope.$broadcast in a component – what is better in terms of performance?

Hi I’m wondering what is better in terms of performance. Let’s say I have this factory that broadcasts stuff: angular.module('core.foo') .factory('Foo', ['$rootScope', function FooFactory($rootScope) { …
chitzui
  • 3,778
  • 4
  • 28
  • 38
6
votes
1 answer

Difference between $rootScope and $rootScope.$root

Is there any difference between $rootScope and $rootScope.$root? What is the difference between $rootScope.global.flag = true and $rootScope.$root.global.flag = true Do both of them access the same variable in rootscope? If so, is there any…
Nithin Baby
  • 7,486
  • 4
  • 21
  • 25
5
votes
1 answer

TypeError: "this..." is not a function

I define hostService as follows. The senario is I call first hostService.addListener() in the controller, then the controller may emit a message by $rootSceop.$emit, hostService is supposed to handle it. app.service('hostService', ['$rootScope',…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292
5
votes
6 answers

Show and hide using $rootscope

I have a search bar in my index.html template that I need to hide on some pages. I am using ui-router and $state. The only way I can make this work is to inject $rootscope into all my controllers to either ng-hide: true or false to turn them on or…
ottz0
  • 2,595
  • 7
  • 25
  • 45
5
votes
1 answer

access $scope from $rootscope angularjs

I would like to know if there is a way to access the $scopes variables using the $rootScope such that if a function is defined in scope I can invoke it using $rootscope to or if there is a variable defined using $scope.var1 I could access it using…
Gardezi
  • 2,692
  • 2
  • 32
  • 62
4
votes
2 answers

How to call a rootscope fuction in html - Angular Js

i have made a rootscope function in which I am actually logging out the user. But I dont know how to call it in a view . My functions is $rootScope.logout = function () { $cookies.remove('auth_token'); …
Usman Iqbal
  • 2,379
  • 5
  • 26
  • 50
4
votes
1 answer

Image loading issue in custom directive

I want the image URL received from server side in my custom directive. The directive is used to create a canvas. Seems the directive is loaded and the image URL is undefined. As it takes the time to get the URL from the server side. Or maybe how did…
Chirag
  • 567
  • 5
  • 20
4
votes
3 answers

Why use $rootScope to share data across controllers when factories can do the same thing?

My understanding is that $rootScope is some kind of global variable which allows it to be shared across controllers. Factories can also do the same thing. So, why not use a factory instead? When should one use $rootScope and when should one use…
3
votes
2 answers

AngularJS $rootScope.$on alternative in context of migration to Angular2

Our AngularJS project had start it's long way to the modern Angular. The ngMigration util recommend me to remove all the $rootScope dependecies because Angular doesn't contain a similar concept like $rootScope. It is pretty simple in some cases but…
kirill.login
  • 899
  • 1
  • 13
  • 28
3
votes
1 answer

$rootScope event preventDefault doesn't stop succeeding handler

I'm using ui-router and registered two $stateChangeStart handlers for login page redirection. function func1(e,to,toParams, from, fromParams){ .... if (notAuthenticated) { e.preventDefault(); $state.go('login'); …
addlistener
  • 871
  • 1
  • 12
  • 20
3
votes
2 answers

Angular: Reload $rootscope user before initializing controller

I'm working on a SPA with AngularJS. After the sign in, a cookie is created with a token and a user object is stored in $rootScope.user which is conveniently accessible from various controllers as they are dynamically loaded. The application works…
1
2 3
10 11