3

In a polymer element I can bind a property like this: <input type="text" value="{{value}}"> But if I create the html element dynamically in the script: TextInputElement newElement = new TextInputElement(); How can I achieve the binding?

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
burktelefon
  • 988
  • 2
  • 8
  • 27

2 Answers2

2

You can have a look at

there was a similar question for Polymer.js recently with a simpler solution (Data binding for dynamically generated HTML in Polymer?) but I haven't seen anything similar for Polymer.dart yet.
I'll try to find something tomorrow, it's rather late here already ...

I created this issue http://dartbug.com/21029 This is fixed now with injectBoundHtml. See also https://groups.google.com/a/dartlang.org/d/msg/web/uqri0fpGH10/dPm169WUiUwJ for more details.

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
0

I use this workaround (polymer 0.15.5+4):

var template = new TemplateElement()
..setInnerHtml("<p>Reversed: {{ reversed }}</p>");
var fragment = this.instanceTemplate(template);
this.shadowRoot.append(fragment);

But it seems rather complex for me and i've not found more elegant solution for a while.

I feel confused by Günter's phrase "The used expressions must already be used somewhere so Smoke knows to generate code for them." from Dart: Dynamic usage of polymer-ui-tabs and polymer-ui-pages does not work thread. Can somebody from this thread light this moment?

Community
  • 1
  • 1
TSV
  • 7,538
  • 1
  • 29
  • 37
  • lf `reversed` isn't already used anywhere in a binding (which is not injected but static) Smoke doesn't generate code and the binding will not work in HTML added dynamically with injectBoundHtml. – Günter Zöchbauer Mar 25 '15 at 21:03
  • Thank you, Günter. Do you know - is there are any program means to make smoke generate missing code at runtime? – TSV Mar 26 '15 at 06:22
  • I'm not sure I understand the question. They can't generate code for expressions they don't know about. – Günter Zöchbauer Mar 26 '15 at 06:24
  • I generate form dymanically and i'd like to tell "smoke" somehow, that I need access some properties in model. Something like "smoke.registerProperty(targetModel, 'path.to.property.i.want.to.use.in.binding')"... – TSV Mar 26 '15 at 06:28
  • Then you need to add this expression somewhere as a dummy expression statically. – Günter Zöchbauer Mar 26 '15 at 16:01
  • 1
    The thing is that I do not know expressions before form creation, i want to create form from metadata describing it. So I'll dig polymer expressions and smoke the smoke :) – TSV Mar 26 '15 at 17:07