Polymer 1.0 custom fire events not caught
I have a problem finding a custom event that is triggered from my login element using a button to my-overview element. I really don't know why this doesn't work.
index.html
<iron-pages attr-for-selected="data-route" selected="{{route}}">
<section data-route="login">
<paper-material id="pmLogin" elevation="1">
<paper-toolbar>
<h1 class="paper-font-display1"><span>Login</span></h1>
</paper-toolbar>
<my-login id="elLogin"></my-login>
</paper-material>
</section>
<section data-route="overview">
<paper-material id="pmOverview" elevation="1">
<paper-toolbar>
<h1 class="paper-font-display1"><span>Overview</span></h1>
</paper-toolbar>
<my-overview id="elOverview"
on-call-overview-refresh="reloadOverview">
</my-overview>
</paper-material>
</section>
</iron-pages>
my-login.html
routeTo: function(route) {
var app = document.querySelector('#app');
app.route = route;
this.fire('call-overview-refresh');
},
my-overview.html
source to share
In short, you must declare on-*
an event handler on the element that is actually fired by the custom event. In this case<my-login>
Seeing what's yours <iron-pages>
in index.html I assume the markup is wrapped inside <template is="dom-bind"></template>
? If so, yours index.html
might look something like this:
<template id="app" is="dom-bind">
...
<iron-pages attr-for-selected="data-route" selected="{{route}}">
<section data-route="login">
<paper-material id="pmLogin" elevation="1">
<paper-toolbar>
<h1 class="paper-font-display1"><span>Login</span></h1>
</paper-toolbar>
<my-login id="elLogin"
on-call-overview-refresh="callReloadOverview"></my-login>
</paper-material>
</section>
<section data-route="overview">
<paper-material id="pmOverview" elevation="1">
<paper-toolbar>
<h1 class="paper-font-display1"><span>Overview</span></h1>
</paper-toolbar>
<my-overview id="elOverview"></my-overview>
</paper-material>
</section>
</iron-pages>
...
</template>
<script>
window.addEventListener("WebComponentsReady", function (e) {
var app = document.querySelector("#app");
app.callReloadOverview = function () {
app.$.elOverview.reloadOverview();
}
...
});
</script>
In the above snippet, when the event <my-login>
fires call-overview-refresh
, the callReloadOverview()
function will be called, which in turn will call the <my-overview>
reloadOverview()
method.
source to share