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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:11:28+00:00 2026-06-04T09:11:28+00:00

In Ember.js, creating a observer which reacts to changes in sub-properties which is an

  • 0

In Ember.js, creating a observer which reacts to changes in sub-properties which is an array leads to non intuitive behavior. If the observer directly observes the array property, it fails to fire while if it observes a binding to the same property, it works as expected.

A simple example:

Handlebars:

<script type="text/x-handlebars">
    <b>App.View1.name:</b> {{App.View1.name}} <br />
    <b>App.View2.name:</b> {{App.View2.name}}
</script>

Javascript:

App = Em.Application.create();

// A common dependency for two views
var dependency = Em.Object.create({
    prop: []
});

// Directly observes dependency.prop
App.View1 = Em.View.create({
    dependency: dependency,
    name: "Foo",
    changeName: function () {
        this.set("name", "Bar");
    }.observes("dependency.prop")
});

// Indirectly observes dependency.prop via a binding
App.View2 = Em.View.create({
    dependency: dependency,
    name: "Foo",
    changeName: function () {
        this.set("name", "Bar");
    }.observes("prop"),
    propBinding: "dependency.prop"
});

// Updating the 'prop' property of dependency with an element.
dependency.get("prop").pushObject("An object.");

I have put it up on JSFiddle here: http://jsfiddle.net/kbaXG/50/

Here, App.View1.name is NOT updated (stays “Foo”) while App.View2.name is updated (to “Bar”).

Is this expected behavior and is creating a binding an acceptable workaround?

  • 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-04T09:11:30+00:00Added an answer on June 4, 2026 at 9:11 am

    Bindings is a fundamental concept in Ember.js, so don’t hesitate to use it 🙂

    Your example works if you create a binding for your dependency, see http://jsfiddle.net/pangratz666/Gqc7Q/:

    App = Em.Application.create({
        VERSION: "0.1"
    });
    
    App.dependency = Em.Object.create({
        prop: []
    });
    
    App.View1 = Em.View.create({
        dependencyBinding: 'App.dependency',
        name: "Foo",
        changeName: function () {
            this.set("name", "Bar");
        }.observes("dependency.prop")
    });
    
    App.View2 = Em.View.create({
        dependencyBinding: 'App.dependency',
        name: "Foo",
        changeName: function () {
            this.set("name", "Bar");
        }.observes("prop"),
        propBinding: "dependency.prop"
    });
    
    // Updating the 'prop' property of dependency.
    dependency.get("prop").pushObject("An object.");
    

    UPDATE

    The problem was that you are changing the contents of an array and not the array itself. So you have to change the observer path to dependency.prop.@each, see http://jsfiddle.net/pangratz666/3QccA/. But I don’t know why it’s working with the binding approach and not with this one… You should file a ticket on GitHub.

    As a last note, the above solution using bindings is the approach which is more Ember like …

    var dependency = Em.Object.create({
        prop: []
    });
    
    App.View1 = Em.View.create({
        dependency: dependency,
        name: "Foo",
        changeName: function () {
            this.set("name", "Bar");
        }.observes("dependency.prop.@each")
    });
    
    App.View2 = Em.View.create({
        dependency: dependency,
        name: "Foo",
        changeName: function () {
            this.set("name", "Bar");
        }.observes("prop"),
        propBinding: "dependency.prop.@each"
    });
    
    // Updating the 'prop' property of dependency.
    dependency.get("prop").pushObject("An object.");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a web application in which teachers need to be able to easily
I am creating a new build process for a DotNet project which is to
I'm creating a mobile app in which I need to show a calendar with
I'm creating a print stylesheet for a webpage which, next to text content, also
I am creating a JavaScript widget which gets around 4-6KB of data from a
I am creating a process in BPEL (say findRules) which has three Java Embeded
I am creating a BPEL process, in which my requirement is I need to
We're creating a desktop application which will use OLAP server to perform analysis. I'm
I am creating an application in which i have used four custom view.I have
With ember-data I'm loading all records of a model with: App.adapter = DS.Adapter.create({ findAll:

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.