This Stack Overflow answer suggests using <iron-signals>
to broadcast an event down the DOM tree to a custom element.
Below, I ask a different question.
Question
How do I:
- pass an event down to a direct child node (custom element)
- from a parent (custom element)
- without using
<iron-signals>
?
Code
This is what I have so far. But it doesn't work.
parent-element.html<dom-module id="parenet-element">
<template is="dom-bind">
<child-element></child-element>
<paper-button on-tap="_handleTap"></paper-button>
</template>
</dom-module>
<script>
(function(){
Polymer({
is: 'parenet-element',
_handleTap: function() {
this.fire("my-event");
}
});
})();
</script>
child-element.html
<dom-module id="child-element">
...
</dom-module>
<script>
(function(){
Polymer({
is: 'child-element',
listeners: {
"my-event": "foo"
},
foo: function(){
// Do stuff
}
});
})();
</script>
child-element
? for example,<dom-module id="parent-element">
<template is="dom-repeat" it>
<child-element></child-element>
</template>
</dom-module>
in this situation, thequerySelector
will just fire the event for first element that it matches, andquerySelectorAll
will fire the event for all items at once. I want one at a time. Any idea? – Bridgeport