To my knowledge there's no way to pass arguments to the constructor. But it
brings up the bigger question of how do you kickoff an element when it
requires more than one attribute to be set. geelen, who created x-gif, and
some of the folks from Mozilla were discussing it recently:
https://gist.github.com/geelen/2e314d9c547b752603fd


On Mon, Aug 11, 2014 at 8:03 PM, <[email protected]> wrote:

> Hi,
>
> I'm using polymer in my project and it works well. Until recently I'm
> start create my CustomElement dynamically. Basically I define a template
> and a constructor so that I can create my CustomElement by constructor in
> script.
>
> I notice when I call the the constructor, the created and ready event will
> be triggered immediately. That makes me hard to adjust settings for
> CustomElement.
>
> For example, I have the following template:
>
> <polymer-element
>     name="fire-ui-unit-input"
>     constructor="FireUnitInput"
>     >
> <template>
> <link rel="stylesheet" href="unit-input.css">
>
>
> <input id="input"
>     class="input"
>     type="text"
>     placeholder="-"
>     ></input>
> <span class="unit">{{unit}}</span>
> </template>
>
> <script>
>     Polymer('fire-ui-unit-input', {
>         publish: {
>             value: null,
>             unit: '',
>             type: 'int', // int, float
>             precision: 2,
>             interval: null,
>             min: null,
>             max: null,
>             focused: {
>                 value: false,
>                 reflect: true
>             },
>         },
>
>         ready: function() {
>             switch ( this.type ) {
>                 case 'int':
>                     this._min = (this.min!==null) ? parseInt(this.min) :
> Number.NEGATIVE_INFINITY;
>                     this._max = (this.max!==null) ? parseInt(this.max) :
> Number.POSITIVE_INFINITY;
>                     this._interval = (this.interval!==null) ?
> this.interval : 1;
>                     break;
>             }
>         },
>     }
>
> </script>
> </polymer-element>
>
> And In some case I have to dynamically create this CustomElement like this:
>
> var unitInput = FireUnitInput();
> unitinput.unit = 'cm';
> unitinput.type = 'float';
>
> Since the constructor of my CustomElement immediately call ready(), I
> don't have a chance to pass unit and type attributes to it. In the code
> above, I have to manually call unitInput.ready() again or some other
> function to do the init stuff.
>
> My question is: is there a way to let the CustomElement's constructor
> receive attributes from code?
>
> Follow Polymer on Google+: plus.google.com/107187849809354688692
> ---
> You received this message because you are subscribed to the Google Groups
> "Polymer" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/polymer-dev/5e554576-0ddb-45b2-9f4d-3e38d8f4e326%40googlegroups.com
> <https://groups.google.com/d/msgid/polymer-dev/5e554576-0ddb-45b2-9f4d-3e38d8f4e326%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

Follow Polymer on Google+: plus.google.com/107187849809354688692
--- 
You received this message because you are subscribed to the Google Groups 
"Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/polymer-dev/CAJj5OwC-Yo%3DYkNv_KW-aDAhUokjvyqxQNGAYJ%2Br_%2ByAiepA%3DmA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to