Gonzalo Pezzi
Gonzalo Pezzi

Reputation: 595

Create a Polymer.Dart element that works with a template provided by the user

I am trying to create a polymer element that would let the user provide a template so that a bunch of items will be created according to that template.

I thought looking at the code of core-list-dart could be a good starting point, as it works exactly that way:

<core-list-dart id="list" data="{{data}}">
  <template>
    <div>Hello, {{model.name}} {{model.surname}}</div>
  </template>
</core-list-dart>

However, I have been looking at the code for some time and I can't find where it creates the elements and adds them to the DOM.

I suppose it has something to do with the use of the package template_binding but I still have no clue how to use it.

Can anyone point me in the right direction? Thanks in advance

Upvotes: 2

Views: 62

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657308

I also think core_list_dart is a good example. Take a look at the attached() method.
At first the template tag is looked up among the children, then the template is registered with templateBind. The initializeData method sets the model

templateBind(template).model = _physicalData;
template.attributes['repeat'] = '';

You might not need the repeat when you don't use a collection as data.

I suggest you try it so far and post your code with the error you get or what doesn't work as expected.

Upvotes: 1

Related Questions