I have a custom element with some models. Here is the code for custom element.
message-element.html
<polymer-element name="message-element" attributes="message">
<template>
<table class="table">
<tr template repeat="{{attrib in attribs}}">
<td><paper-input name="message-attrib-name" label="New Attribute" value="{{attrib.name}}"></paper-input></td>
<td>
<paper-input name="message-attrib-value" label="" value="{{attrib.value}}"></paper-input>
<core-icon-button icon="check" on-tap="{{addAttribute}}"></core-icon-button>
<core-icon-button icon="highlight-remove" on-tap="{{deleteAttribute}}"></core-icon-button>
</td>
</tr>
</table>
</template>
<script type="application/dart" src="message-element.dart"></script>
</polymer-element>
message-element.dart
@CustomTag('message-element')
class MessageElement extends PolymerElement with Observable {
@published Message message;
@observable List<Attribute> attribs = toObservable([]);
@observable Attribute att;
/// Constructor used to create instance of MainApp.
MessageElement.created() : super.created() {
polymerCreated();
}
attached() {
att = new Attribute('', '');
attribs.add(att);
message.attributes = attribs; // initialize with 1 attrib
}
void addAttribute(Event event, Object detail, Node sender) {
att = new Attribute('', '');
attribs.add(att);
}
void deleteAttribute(Event event, Object detail, Node sender) {
// remove the clicked attrib
}
}
attribs is shown in a modal dialog and each attrib in attribs has couple inputs with add and delete buttons. Adding element is working fine. How do I delete the clicked attrib from attribs. I'm calling void deleteAttribute(Event event, Object detail, Node sender) on on-tap on delete button. In this call I need to delete the attrib from the list but how do I get the details of tapped attrib so I can delete that from the list.