I encounter strange behavior following the examples on the polymer website for creating custom events and delegation ( https://www.polymer-project.org/articles/communication.html ). I have tabs with polymer tabs that trigger my custom event when the tab changes, and now I'm trying to have my other user element listen for the event and respond, but I don't see something explicitly, since the event does not go up from inside of ready (). However, if I tie it to the window, I see that it works without any problems, so it would be possible to evaluate the second pair of eyes :)
This is a custom item that fires an event when tabs change:
<polymer-element name="pm-tabmenu"> <template> <style> :host { display:block; } </style> <paper-tabs selected="1" id="tabmenu"> <paper-tab id="pm-tabmenu-all" state="all">All</paper-tab> <paper-tab id="pm-tabmenu-wip" state="wip">In Progress</paper-tab> <paper-tab id="pm-tabmenu-finished" state="finished">Finished</paper-tab> </paper-tabs> </template> <script> Polymer({ ready: function () { var tabs = this.$.tabmenu; tabs.addEventListener('core-select', function (event) { if (event.detail.isSelected) { this.fire("pmtabmenuselect", { state: event.detail.item.getAttribute('state') }); alert(event.detail.item.getAttribute('state')); } }); } }); </script> </polymer-element>
This is how I want to capture an event in another user element:
<polymer-element name="pm-list"> <template> <style> :host { display:block; } </style> <h1> Current filter: {{filter}}</h1> </template> <script> window.addEventListener('pmtabmenuselect', function (e) { alert("This does fire"); }); Polymer({ filter: "Not yet defined", ready: function () { this.addEventListener('pmtabmenuselect', function (e) { alert("This does not fire"); }); } }); </script> </polymer-element>
In the index file, both elements are included, and then called, but there is no section, since I do not think that it is needed at the moment.
<core-header-panel flex main> <core-toolbar class="medium-tall"> <paper-icon-button icon="menu" core-drawer-toggle></paper-icon-button> <div flex>Tests</div> <paper-icon-button icon="search"></paper-icon-button> <paper-icon-button icon="more-vert"></paper-icon-button> <div class="bottom fit" horizontal layout> <pm-tabmenu flex style="max-width: 600px;"></pm-tabmenu> </div> </core-toolbar> <pm-list></pm-list> </core-header-panel>
Edit: Additional information is provided upon request.
Edit2: Added using item code.