Search code examples
polymerpolymer-2.xdom-repeat

How to Push Data to dom-repeat


I am trying to push data to a history array that will be updated inside a dom-repeat template.

Template

<paper-button on-tap="_addToHistory">Add to History</paper-button>

<template is="dom-repeat" items="{{history}}">
  <h3 class="test">[[item.name]]</h3>
</template>

Properties

history: {
  type: Array,
  value: []
}

Functions

_addToHistory() {
  this.history.push({"name": "Computer"});
}

When I log out history I see an array of objects, but nothing is appended to the dom when _addToHistory is called.

How can I setup a dom-repeat template to respond to an object updating?


Solution

  • Use this.push('history', {"item"}) to notify the template to update with fresh data.