Search code examples
polymerpolymer-1.0web-component

Complete example of Polymer Two Way Binding


The polymer documentation has the following two way binding example:

    <script>
      Polymer({
        is: 'custom-element',
        properties: {
          someProp: {
            type: String,
            notify: true
          }
        }
      });
    </script>
    ...

    <!-- changes to "value" propagate downward to "someProp" on child -->
    <!-- changes to "someProp" propagate upward to "value" on host  -->
    <custom-element some-prop="{{value}}"></custom-element>

I'm looking for a complete example that includes the design of the child, programmatic and interactive events the can cause upward and downward propagation of the `{{value}} property, and a demo of of the complete setup / example.


Solution

  • Here are some examples on js fiddle that demonstrate different ways of binding:

    • Two-way binding:

      https://jsfiddle.net/tej70osf/
    • One-way binding: notify is not set on value property of the child element:

      https://jsfiddle.net/tej70osf/1/
    • One-way binding: notify is set to true true on value property of the child element however the value property is bound using square brackets [[value]] instead of {{value}}:

      https://jsfiddle.net/tej70osf/2/

    Hope that helps