Aurelia Custom Elements data binding

Sayan Pal

I am using a custom-element with my Aurelia app. When I am binding data from my view-model with the custom-element, it is working fine. Even if I make some changes in the data in the custom-element control, the change is also reflected to the data in my view model, thanks to the two-way data binding.

However, if I make some changes in the data from the view model (using javascript), the data is not updated in the custom-element. I have replicated this problem for a simpler setting.

Simple View Model

export class Playground {

  public testObj: any;
  counter = 0;


  constructor() {
    this.testObj = {
        prop1: "This is prop1 value"           
        , collection2: [{ id: "item21" }]
    }        
  }

  updateProp1() {
    alert("before update: "+this.testObj.prop1);
    this.testObj.prop1 = "Sayan " + this.counter++;
    alert(this.testObj.prop1);
  }

  verifyChange() {
    alert(this.testObj.prop1);
  }
}

Simple View

<template>
<h1>
    Playground
</h1>

<div >         
    <div repeat.for="item of testObj.collection2">
        <div class="row">
            <div class="col-sm-4">
                <input type="text" class="form-control" placeholder="prop1"
                       value.bind="$parent.testObj['prop1']">
            </div>
        </div>
    </div>

    <button click.delegate="updateProp1()" class="btn btn-primary"> Update Prop1 </button>
    <button click.delegate="verifyChange()" class="btn btn-primary"> Verify Change </button>

</div>

</template>

Now whenever I click Verify Change after changing the value in textbox, the changed value comes in the alert. But, if I click the Update Prop1 button, the prop1 value gets updated, but the change doesn't reflect in the view. I am not sure exactly what I am missing.

Note: Instead of using $parent.testObj['prop1'], if $parent.testObj.prop1 is used, the databinding works as it should. However, my actual custom-element is of generic kind and the property name is not known before hand, hence it seems that I need to keep using $parent.testObj['prop1'] notation instead of dot notation: $parent.testObj.prop1.

At pointer/suggestion/feedback is appreciated.

Update: If anyone can point out the the difference between the dot notation and indexer notation w.r.t. aurelia data-binding (I have checked this already), that will be of great help.

Jeremy Danyow

This was an issue in earlier builds of the aurelia/binding module. Here's the related issue(s):

I tried your view/view-model in the latest version of aurelia and everything worked. Here's a screencast of what I saw: http://screencast.com/t/KqcuqXWjkU2

Make sure you have the latest version of the aurelia components installed- update steps here: http://blog.durandal.io/2015/05/01/aurelia-may-status-and-releases/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Aurelia Custom Elements data binding

From Dev

Aurelia binding hook on "nested" data update in custom element

From Dev

Data binding between sibling custom elements

From Dev

Update a binding in an Aurelia custom attribute

From Dev

Aurelia: Binding textContent of a custom element?

From Dev

Adding custom elements to aurelia view

From Dev

Binding to a Custom Element in a Template Part in Aurelia

From Dev

Aurelia: Custom Elements vs Custom Attributes

From Dev

Data binding parent-child relationships in Aurelia

From Dev

Aurelia - Using variable as name of property in data binding

From Dev

How can Aurelia custom elements interact?

From Dev

Nested Custom Elements in Aurelia not rendering as expected

From Dev

Data binding to custom UserControl

From Dev

Data Binding - communicating between 2 custom elements within another custom element

From Dev

Aurelia - Accessing ViewModel functions/binding from within Generated DOM elements

From Dev

Aurelia - Accessing ViewModel functions/binding from within Generated DOM elements

From Dev

Two-way binding between parent and child custom element in Aurelia

From Dev

Aurelia two-way binding in custom element not working

From Dev

Aurelia custom binding with Parent resolver not injecting correct container

From Dev

Aurelia two-way binding in custom element not working

From Dev

Android data binding with custom adapter

From Dev

Binding data in a custom directive - AngularJS

From Dev

Angular Custom Directive Data Binding

From Dev

Angular Custom Directive Data Binding

From Dev

data binding to custom dropdown with Vuejs

From Dev

Custom User Control not binding data

From Dev

Custom Href Data Binding KnockoutJs

From Dev

how to add and remove custom elements on the fly or by an click event in aurelia

From Dev

how to add and remove custom elements on the fly or by an click event in aurelia

Related Related

  1. 1

    Aurelia Custom Elements data binding

  2. 2

    Aurelia binding hook on "nested" data update in custom element

  3. 3

    Data binding between sibling custom elements

  4. 4

    Update a binding in an Aurelia custom attribute

  5. 5

    Aurelia: Binding textContent of a custom element?

  6. 6

    Adding custom elements to aurelia view

  7. 7

    Binding to a Custom Element in a Template Part in Aurelia

  8. 8

    Aurelia: Custom Elements vs Custom Attributes

  9. 9

    Data binding parent-child relationships in Aurelia

  10. 10

    Aurelia - Using variable as name of property in data binding

  11. 11

    How can Aurelia custom elements interact?

  12. 12

    Nested Custom Elements in Aurelia not rendering as expected

  13. 13

    Data binding to custom UserControl

  14. 14

    Data Binding - communicating between 2 custom elements within another custom element

  15. 15

    Aurelia - Accessing ViewModel functions/binding from within Generated DOM elements

  16. 16

    Aurelia - Accessing ViewModel functions/binding from within Generated DOM elements

  17. 17

    Two-way binding between parent and child custom element in Aurelia

  18. 18

    Aurelia two-way binding in custom element not working

  19. 19

    Aurelia custom binding with Parent resolver not injecting correct container

  20. 20

    Aurelia two-way binding in custom element not working

  21. 21

    Android data binding with custom adapter

  22. 22

    Binding data in a custom directive - AngularJS

  23. 23

    Angular Custom Directive Data Binding

  24. 24

    Angular Custom Directive Data Binding

  25. 25

    data binding to custom dropdown with Vuejs

  26. 26

    Custom User Control not binding data

  27. 27

    Custom Href Data Binding KnockoutJs

  28. 28

    how to add and remove custom elements on the fly or by an click event in aurelia

  29. 29

    how to add and remove custom elements on the fly or by an click event in aurelia

HotTag

Archive