Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 617
Ole Avatar asked Feb 06 '23 03:02

Ole


2 Answers

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

like image 136
Ahmed El Kilani Avatar answered May 04 '23 11:05

Ahmed El Kilani


<dom-module id="user-demo">
<template> 
<paper-input label="FIRST NAME" value="{{firstName}}"></paper-input>
</template>
</dom-module>
<user-demo></user-demo>

In your javascript code:

 Polymer({
        is: 'user-demo',
        properties: {
            firstName: {
                type: String,
                value: 'John',
                notify: true
            }
        }
});

Check out the following fiddle for the full example: https://jsfiddle.net/meenakshi_dhanani/6ffwh0qv/

I tried to use more polymer elements and two way binding. Hope it helps

like image 37
meenakshi Avatar answered May 04 '23 12:05

meenakshi