Skip to content

Using scoped models impacts 2-way property binding #220

Description

@sorvell

Given this type of usage:

<polymer-element name="x-thing">
  <template>
    <template repeat="{{user in users}}">
      <x-item manager="{{manager}}"></x-item>
    </template>
  </template>
  <script>
    Polymer('x-thing', {
      ready: function() {
        this.manager = {name: "Bob"};
      }
    });
  </script>
</polymer-element>

The expectation here is that x-thing's manager property is bound directly to x-item's manager property.

However, the use of the scoped model {{user in users}} makes the binding 1-way instead of 2-way. The model used to populate x-item is no longer x-thing but instead an object with a user property an x-thing as its prototype. Therefore, when x-item sets manager is does not change the value in x-thing.

This behavior can be worked around by setting a reference to the element inside itself like this:

<polymer-element name="x-thing">
  <template>
    <template repeat="{{user in users}}">
      <x-item manager="{{self.manager}}"></x-item>
    </template>
  </template>
  <script>
    Polymer('x-thing', {
      ready: function() {
        this.self = this;
        this.manager = {name: "Bob"};
      }
    });
  </script>
</polymer-element>

Activity

  1. ghost assigned on Sep 25, 2013
  2. sorvell commented on Aug 13, 2014

    @sorvell
    ContributorAuthor

    This has been fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions