All Questions
Tagged with angularjs-rootscope angularjs
148
questions
32
votes
5answers
29k views
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 ...
8
votes
3answers
11k views
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 ...
8
votes
4answers
860 views
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 ...
6
votes
1answer
550 views
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 ...
5
votes
3answers
9k views
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 ...
5
votes
1answer
4k views
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 ...
5
votes
6answers
2k views
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 ...
4
votes
3answers
669 views
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 ...
4
votes
1answer
3k views
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 ...
4
votes
1answer
610 views
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 ...
3
votes
2answers
3k views
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....
3
votes
2answers
2k views
AngularJS - Accessing ng-init variables from run method
1) I have variables initialized in ng-init
Eg -
ng-init="password='Mightybear'";
2) I want to access it from the .run method.
Eg -
anguar.module("ngApp", [])
.run(function() {
//Access ...
3
votes
1answer
442 views
$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....
3
votes
4answers
1k views
I am unable to access $rootScope in my controller
I have some parameters in the $rootScope as specified below:
myApp.factory('itemService', function($http) {
return $http.get('/items');
});
myApp.run(function($rootScope, itemService) {
...
3
votes
1answer
8k views
TypeError: “this…” is not a function [duplicate]
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 ...
3
votes
2answers
3k views
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 ...
2
votes
2answers
83 views
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 $...
2
votes
3answers
709 views
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??
2
votes
3answers
74 views
AngularJS Code Understanding
Can someone please help me explain this code segment in AngularJS
$rootScope.compiledScope = $scope.$new(!0, $rootScope), $scope.variable = "someValue";
What is $new operator serving here
What is !0?...
2
votes
2answers
191 views
Rootscope not accessible in function
In the code below I log to console the $rootScope and it logs undefined.
Why does it happen?
$scope.init = function ($rootScope) {
// var s = $cookies.get("arr");
// var ex = [];
var ex ...
2
votes
2answers
576 views
Route change events while trying to avoid using $rootScope
As the Angular team (and severals blogs) adviced, I try to avoid using $rootScope as possible in my apps.
$rootScope exists, but it can be used for evil
"Of course, global state sucks and you ...
2
votes
1answer
2k views
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?
...
2
votes
1answer
933 views
Angular Broadcast not working
I am unable to broadcast to other controllers as I have no parent child relation ship therefore, using $rootScope to broadcast the change to other controllers.
Please help me to identify the problem ...
2
votes
1answer
23 views
Fetch server settings after boostrap but before anything else
I've been searching for an answer for this but haven't got any unambiguous or clear answer on how to solve and come about this.
In my anguarJS app, I want to make sure that the very first thing after ...
2
votes
0answers
63 views
Error while testing promise with Jasmine unit test
I've been writing some unit tests in Jasmine and I have a function that returns a promise in a service which I use in my own factory. I'm doing the following steps:
inject(function(_$rootScope_, _$q_,...
1
vote
2answers
906 views
$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 ...
1
vote
3answers
1k views
$rootScope.$broadcast on $rootScope.$on: RangeError: Maximum call stack size exceeded
I want to define page title in angular like this :
a standard PageController :
angular.module('admin').controller('AdminController',
function($scope) {
// emit an event to rootscope
...
1
vote
3answers
3k views
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 ...
1
vote
3answers
1k views
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 ...
1
vote
2answers
515 views
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.
...
1
vote
1answer
225 views
Is there something similar to angular $rootScope in Polymer.dart?
I know that in angular exists something called $rootScope. This one contains variables that are going to be shared by all the controllers. I'm looking for something similar for Polymer, so that I don'...
1
vote
1answer
14 views
Accessing rootScope variable in template view not working
I know this is possible and have seen many threads on how to do this but I can't figure out what I am doing wrong. My $rootScope variable is not appearing in my template view.
.run(function($...
1
vote
1answer
42 views
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....
1
vote
1answer
2k views
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:
<select ng-model="$parent.proizvod" ng-options="i.id_proizvod as i.proizvod for i in proizvodiServer">
...
1
vote
1answer
521 views
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 ...
1
vote
1answer
297 views
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 ...
1
vote
2answers
3k views
Run a function every time an Angular controller is loaded
I want to run a function every time any Angular controller is loaded.
The best way I have found is to attach this handler in the first controller loaded on my site:
$rootScope.$on('$...
1
vote
1answer
258 views
Custom expiration date directive throwing rootScope digest error
I have 2 input fields that need to get validated after both fields have been entered. It's a credit card expiration date, so theres a month and year. I'm using a third-party service to actually do the ...
1
vote
0answers
123 views
AngularJS multi screen validation on last step
I have an angularJS application. I have implemented a generic workflow using $routeProvider, templateUrl & Controllers.
Each step(screen) is verified when user click on next button and moves to ...
1
vote
0answers
645 views
find the cause of Error: [$rootScope:inprog] $apply already in progress
My application has a dashboard with some panels, each one with a chart.(I use Angular-Chart.js) Each panel is a different custom directive.
I have TickService with a global tick, broadcasted each ...
1
vote
2answers
46 views
Multiple parent-child scope event trigger issue
I have a directive for parent scope, I also have another directive for child scope. In a template, I have several parent-child scope. Like this.
ParentScope1
- ChildScope1
ParentScope2
- ...
1
vote
1answer
228 views
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....
1
vote
0answers
314 views
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 = {};
...
1
vote
0answers
21 views
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 ...
1
vote
0answers
125 views
Access $rootScope value in Kendo Grid for export to excel dynamic file name
This is HTML
------------
<div class="lm-panel panel panel-default">
<div class="lm-panel-...
1
vote
1answer
165 views
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-...
1
vote
0answers
155 views
Convert this $rootScope to factory used in http basic authentication angularjs
I am using this example to build a HTTP Basic authentication app with angularjs.
http://jasonwatmore.com/post/2014/05/26/AngularJS-Basic-HTTP-Authentication-Example.aspx
The writer uses $rootScope to ...
1
vote
2answers
2k views
$rootScope is undefined in controller
I am getting very strange issue in angular. I have defined $rootScope.user_info in run method. But when i am fetching the root scope in controller, sometimes i am getting undefined method $rootScope....
1
vote
1answer
386 views
Adding templateUrl dynamically while setting $routeProvider $ angular.config
I am angular newbie.I would like to achieve following code...
$routeProvider.when('/view', {templateUrl: 'ViewSwitcher?pageId='+$rootSope.pageId+'&userId='+$rootSope..userId+'&token='+$...
1
vote
0answers
504 views
ionic app.run deviceready rootscoop variable not working
In my ionic app I have the app.run function and a device ready function inside it:
app.run(function($rootScope, $ionicPlatform, $cordovaPush) {
document.addEventListener("deviceready", function(){...