rootScope is upating on scope variable update

rootScope is upating on scope variable update

By : user2948227
Date : November 14 2020, 04:48 PM
I wish did fix the issue. This behavior is the way JavaScript works and has nothing to do with AngularJS. JavaScript is an object-oriented (prototype-based) language where objects are addressed by reference and not by value. E.g. assign car2 to car1 and both of them will reference the same object (JSFiddle)
code :
var car1 = {make: "Audi"}
var car2 = car1;
car2.make = "Toyota";
$scope.chillerAttributes = angular.copy(data.ObjCandidateListChillerAttributes);
$scope.chillerConditions = angular.copy(data.ObjCandidateListConditions);

Share : facebook icon twitter icon
$scope variable not update within $rootScope.$on

$scope variable not update within $rootScope.$on

By : noone
Date : March 29 2020, 07:55 AM
I wish this help you This show number 1 and a Change button. When I click that button, it supposed to trigger $state.go and within the controller, it should detect the event in $rootScope.$on and update the number to 2. However, for some reason I cannot get the number (data.id) to update even using $digest or $apply. , The reason is, that you are recreating data every time
code :
// this will create new reference to data
// in current scope, while not effecting any other (parent)
$scope.data = {id: 2}; 
// here we work with existing reference
// if it was created, it will be used, the id property will be updated
$scope.data = $scope.data  || {}; 
$scope.data.id = 2;
    .state('state1Parent', {
      template: '<div ui-view=""></div>',
      controller: 'state1ParentCtrl',
    .state('state1', {
      parent: 'state1Parent',
      url: '/state1/:id',
      controller: 'state1Ctrl',
      templateUrl: 'state1.html'
app.controller('state1Ctrl', function ($scope, $rootScope, $state, $stateParams) {
  // no $scope.data definition, used the inherited
  //$scope.data = {id: 3}; 

  $rootScope.$on('$stateChangeSuccess', function(evt, toState, toParams, fromState, fromParams) {

    // because this state change listener still have access to $scope
    // we can update the value of data.id
    // because it is in fact parent reference
    // se even next state will have access to it

    //$scope.$apply(function() {
      $scope.data = $scope.data || {};  
      $scope.data.id = toParams.id;  

app.controller('state1ParentCtrl', function ($scope, $rootScope, $state, $stateParams) {
  $scope.data = { id : 1 };
app.controller('state1Ctrl', ...
  $rootScope.$on('$stateChangeSuccess', ...
     // HERE - $scope belongs to Controller, and its life cycle is very short
     $scope.data =
$rootScope variable value not upating in Angular filter

$rootScope variable value not upating in Angular filter

By : Shahid thetrendsette
Date : March 29 2020, 07:55 AM
Does that help The problem is because angular instance $filter just once, so your $rootScope in your filter will be old. The best way is just pass your convert_rate as argument to your filter.
See this plunker i've made for you http://plnkr.co/edit/yNea42CeBBG2KNEmugku?p=preview
code :
//In your filter
.filter('convert', function() {
return function(input, convert_rate) {
  var out = parseInt(input) * convert_rate;
  return out;

//Your HTML

{{original_value | convert: convert_rate}}
Scope update after $rootScope event and Promise is not reflected in view

Scope update after $rootScope event and Promise is not reflected in view

By : Mark Ludwinski
Date : March 29 2020, 07:55 AM
To fix this issue What's working for me is that I have an external scope property (scope.someProperty) which is changing as well when my event occurs.
Watching on it does change the scope which is reflected in the view.
code :
(function () {
  'use strict';

    .directive('myDirective', myDirective);

  function myDirective($rootScope, $localStorage, MyPromise, MyService) {
    var linkFunction = function (scope, element, attributes) {

      scope.myValue = null;

      scope.$watch('someProperty', function(newVal){
          MyPromise().get({}, function (result) {
             $localStorage.result = result;
             scope.myValue = MyService.getFromLocalStorageAndReturnStuff();

      function initialize() {


    return {
      restrict: 'A',
      transclude: true,
      replace: true,
      scope: {
        someProperty: '=myProperty'
      link: linkFunction,
      templateUrl: 'myTemplate.html'
Angular: using $rootScope.$on vs $scope.$on to catch a $rootScope.$broadcast in a component – what is better in terms of

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

By : Jes
Date : March 29 2020, 07:55 AM
I hope this helps . I don't really understand why people here seem to be so obsessed with performance. You should only worry about performance when you have a performance problem. Otherwise, it's premature optimization, which is the root of all evil.
In that case, the evil might be memory leaks, and much performance problems.
Access $scope from $rootScope by invoking the method defined in the $rootScope?

Access $scope from $rootScope by invoking the method defined in the $rootScope?

By : Simon Balmes
Date : March 29 2020, 07:55 AM
hop of those help? scope is a hierarchical tree with rootScope sitting on the top with controller scopes as child scopes. If you alter a value attached to the rootscope it would be available to both controllers ie if in ControllerA you set $rootscope.value = 1, controllerB can access $rootScope.value.
However it is not advised to attach values to the rootScope if you can avoid it. It is seen as bad practice in angular similar to setting global values in javascript.
Related Posts Related Posts :
  • AngularJS - Does $resource requests send cookies automatically?
  • Communication between two nested directives angularjs
  • what can or cannot be done with a controller created in a module Vs controller created globally?
  • Angularjs - add ng-* attributes using directives
  • Why are my Angular, absolute path, URL's not compiling properly with Closure Compiler?
  • AngularJS routing not working properly in PhoneGap
  • AngularJS: Create new scope variable name using a variable value
  • Directive scope update does not update controller scope (AngularJs)
  • Unit-test a angular controller function in a directive
  • jQuery Sparkline in a cell in ng-grid using CellTemplate and Directive
  • AngularJS determine filter in controller
  • How to deploy an app using ionic framework to Amazon? (elastic beanstalk prefered)
  • Conditional injection of a service in AngularJS
  • Filtering on object properties not working
  • Open $modal from the service and pass variables to the controller
  • ngClick evaluated against scope instead of isolateScope
  • onEnter and onExit are not called when state is left/activated in angularjs ui router
  • Shared client & server modules with angularjs and pongular
  • Getting the angular app to run when using protractor
  • Angularjs: create a link for download different types of file
  • AngularJS: On Change of Parent DropDown Option Also Changes the Dependant Drop Down Options Associated with Other Parent
  • Angular HTML5 mode, Wordpress, Rewrites, Apache and You
  • Using angular js form validations in <form:input> tag
  • AngularJS call common functions in a directive template
  • AngularJS Promise resolved incorrectly
  • properly clearing whole AngularJS ui-grid chart
  • Can not figure out how to store $rootScope in angular.bootstrap
  • animate.css animation within angularjs 1.3 using ngAnimate gives different animations in Firefox
  • Auth0 IE Issue: Unable to get property 'frames' of undefined or null reference
  • Am I misusing directives with too much logic?
  • Use an Angular JS value as a parameter of TWIG "path" function in Symfony 2
  • multiple function on ng-click angularjs
  • Converting $.ajax call to $http call in angular 404 error
  • Angularjs templateUrl file location not found
  • How to execute the function after change page in angularjs?
  • Pass variable to AngularJS directive without isolated scope
  • OAuth, Custom Login, or Both
  • Angular Directive: Isolate Scope & Transclude is true, but HTML in the directive needs to continue to bind to parent
  • Compare objects in angularjs
  • Combine "Checkbox" & "Avatar" in an Ionic Framework List
  • Issue with the Angular UI router when inheriting from a parent state
  • Is there a way to initialize an Angular Service without DI into controller
  • Why is a parent controller's $scope not accessible from a (child) directive?
  • How to get back button in Ion-tabs page
  • AngularJS bind class attribute to model
  • How can I get AngularJS ui-router to respond correctly to a browser page refresh?
  • Angular validation does not work
  • Breez Create Complex Entities
  • Drag and drop using protractor in dthmlx component
  • In Angular JS, what is the default 'cache' value that is used when sending request with $http service?
  • How to change placeholder for single textbox in angular?
  • $ is not defined - jquery angular mixing
  • CORS issue angularjs and spring security
  • Angularjs cannot select last item in dropdown the first time
  • Angularjs - $watch issue
  • On change radio button to no the span should hide in angular
  • Creating a wordcloud generator in Angularjs
  • Angular UI Bootstrap collapse - whats wrong?
  • AngularJS after redirect from app to app, the default page is not loading
  • Why does my scope update my factory and my factory update my scope when it should not?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org