Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9101217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:04:10+00:00 2026-06-17T01:04:10+00:00

The jsFiddle for this question can be found here: http://jsfiddle.net/Hsw9F/1/ JavaScript ( console.log debug

  • 0

The jsFiddle for this question can be found here: http://jsfiddle.net/Hsw9F/1/

JavaScript (console.log debug information available in the jsFiddle)

var app = angular.module('StackOverflow',[]);

function ParentController($scope) {
 $scope.parentCounter = 5;
}

function ChildController($scope) {
  $scope.childCounter = $scope.parentCounter;
  $scope.increaseCounters = function() {
    ++$scope.parentCounter;
    ++$scope.childCounter;
  };
}

In the example above I have a counter in the parent and the child controllers named parentCounter and childCounter respectively. I’ve also provided a function in the child controller named increaseCounters() that increases both counters by one.

Both of these counters are displayed on the page:

<div ng-app="StackOverflow">
  <div ng-controller="ParentController">

    Parent Counter: {{parentCounter}}<br />

    <div ng-controller="ChildController">
      Child Counter: {{childCounter}}<br />
      <a href="javascript:void(0)"
         ng-click="increaseCounters()">Increase Counters</a>
    </div><!-- END ChildController -->

  </div><!-- END ParentController -->
</div><!-- END StackOverflow app -->

The problem is that AngularJS doesn’t seem to update the {{parentCounter}} on the page, and only updates the {{childCounter}} when the increase counters function is called. Is there anything I have overlooked?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T01:04:12+00:00Added an answer on June 17, 2026 at 1:04 am

    ++$scope.parentCounter; creates a child scope property with name parentCounter that hides/shadows the parent scope property of the same name.

    Add console.log($scope); to your increaseCounters() function to see it.

    One workaround: ++$scope.$parent.parentCounter;

    The problem you are experiencing has to do with the way JavaScript prototypal inheritance works. I suggest reading What are the nuances of scope prototypal / prototypical inheritance in AngularJS? — it has some nice pictures explaining what happens when primitives are created in child scopes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To explain my question I have created this http://jsfiddle.net/Jams/XNVB2/ here I want when div1
I'm trying to implement this example http://jsfiddle.net/gzF6w/1/ (from another question here on stak) on
I found this in a stackoverflow question on how to draw in canvas http://jsfiddle.net/ArtBIT/kneDX/
I found a javascript snow script. Here is the fiddle: http://jsfiddle.net/wj2K4/ (very nice) Its
I have a menu now, that can be found here... http://jsfiddle.net/EUaNY/ Now I'm wanting
i have a very conceptual question regarding jquery. i have this fiddle http://jsfiddle.net/zvCrN/ What
I found this question here on SO and the solution is pretty simple: jsfiddle:
I'll let this jsfiddle describe most of the problem for me. http://jsfiddle.net/zAPVQ/4/ I've got
Have a look at this jsfiddle: http://jsfiddle.net/Dh96F/1/ The Expand button will animate the widening
This fiddle works (see We Distribute under Products): http://jsfiddle.net/dgUFw/1362/ But on the page in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.