Search code examples
javascripteventspolymer

polymer template auto-binding : on-core-select fires before template-bound event


I am using an auto-binding template, which contains some basic core elements such as core-menu and core-submenu. One of the menu elements has an on-core-select event handler defined. When the app loads, the on-core-select event fires before the template-bound event does. Is this expected?


Solution

  • This is often the case if the on-core-select by core-submenu fires before loading the rest of the page, a solution is to set an eventHandler for 'polymer-ready' event.

    Polymer fires a 'polymer-ready' event when all the elements have been loaded on to the page. So you code might look like this:

    window.addEventListener('polymer-ready', function(e) {
          document.querySelector('core-submenu').addEventListener('on-core-select', doSomething());
    });