ovangle
ovangle

Reputation: 2031

What are the scoping rules of a `<template repeat>`

Should bindings created inside a template repeat require an associated property on the polymer element, I thought they were bound to the array items of an ObservableList?

Inside my template is the following code:

<polymer-element name="event-details">
  <template>
    <!-- etc -->
    <template repeat="{{artist in event.artist}}">
      <artist-card artist="{{artist}}">
    </template>
    <!-- etc -->
  </template>
  <!-- etc -->
</polymer-element>

And my element definition looks like

@CustomTag('event-details')
class EventDetails {
   /* etc */
   @published
   api.Event get event => readValue(#event);
   set event(api.Event event) => writeValue(#event, value);
   /* etc */
}

When I create the element, I get the error

"EventDetails has no attribute `artist`"

but I assumed that the artist in the <template repeat> should only exist inside that template's scope. There is no value in having the {{artist}} on the element's definition, as it will only ever point to the last element in the template's children.

artists is an ObservableList on the api.Event object, although it is defined without using polymer.

Upvotes: 1

Views: 54

Answers (1)

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

Reputation: 657308

Use a simple property (field/getter/setter) instead of readValue/writeValue.

Upvotes: 1

Related Questions