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 9128381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:30:03+00:00 2026-06-17T07:30:03+00:00

My index.html looks like this: <div id=div1 ng-controller=StartMenu> <div id=button1 ng-click=doSomething()></div> {{value}} </div> <div

  • 0

My index.html looks like this:

<div id="div1" ng-controller="StartMenu">
  <div id="button1" ng-click="doSomething()"></div>
  {{value}}
</div>
<div id="div2" ng-view></div>

Module configuration:

angular.module('app').config([$routeProvider, function($routeProvider) {
  $routeProvider.when('/start', {
    templateUrl: 'partials/start.html', controller: StartMenu
  });
}]);

start.html:

<div id="button2" ng-click="doSomething()"></div>
{{value}}

And controller function:

function StartMenu($scope, globals) {    // service globals defined elsewhere
  $scope.value = globals.value
  $scope.doSomething = function() {
    // Manipulate globals.value
    $scope.value = globals.value;
  }
}

The problem: These two div elements in index.html share a same controller function. When I click #button1 in #div1 doSomething is invoked and $scope.value is changed. The change is immediately rendered in #div1 and {{value}} changes but #div2 remains unchanged. How do I “force” #div2 to be rendered and to show the change in {{value}}?

  • 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-17T07:30:04+00:00Added an answer on June 17, 2026 at 7:30 am

    ng-view creates its own (child) scope, so the {{value}} in start.html is created on the child scope. This value property hides/shadows the property of the same name in the parent scope. There are a few possible solutions:

    1. use {{$parent.value}} in start.html
    2. use an object instead of a primitive on the parent $scope — e.g., $scope.obj = {value: 2}. Then reference it in the child: {{obj.value}}. (Well, this won’t work for your particular scenario, since value in the parent scope already references something else.)
    3. use a function in start.html: {{value()}} — define that function on the parent scope.

    For more info about scope inheritance, see What are the nuances of scope prototypal / prototypical inheritance in AngularJS?

    Update: I read the HTML too fast… div2 is not contained within div1. The issue is twofold:

    1. two controllers are being created, each of which creates its own value property on its own scope
    2. if globals.value is a primitive, then the controller scopes are getting copies of the values, not references.

    Solutions 2 and 3 above apply here.

    2 = Create an object on globals and reference a property of that object in the controller scopes (i.e., don’t use a primitive).

    3 = use a function in the controllers to access the global primitive value. Fiddles for both solutions are in the comments below.

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

Sidebar

Related Questions

Absolute beginner question: I have a template file index.html that looks like this: ...
I have a block of HTML that looks like this: <div id=header> <h1>title</h1> <h2>subtitle</h2>
Lets say that I have a HTML that looks like this: <div class=aaa><span>1</span></div> <div
I have two DIV elements. HTML looks like this: <div id=first><div id=second></div></div> The CSS
Hello I have some HTML that looks like this, <div id=music_interests> <ul class=interests> <li
Let's say i have an index.php that has html in it that looks like
In my rails view(index.html.erb), i have following structure <div> <%= render :partial => create
Currently my code results in a view that looks like this: Lessons Start Now!
I had tabs with preloaded content like this: $(function () { $('div.tabs ul.tabNavigation a').click(function
I have a view in a .js file apart the 'index.html' file which looks

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.