Polymer.fire is not a function -


my web-component (polymer 1.0) changes light-dom given <content> , tries convert click custom event.

<link rel="import" href="path/to/polymer.html"> <dom-module id="x-custom">     <template>         <content></content>         <!-- used way <x-custom><div></div></x-custom> -->     </template>      <script>     (function() {          function init() {             var myroot = polymer.dom(this);             var firstdiv = myroot.queryselectorall("div")[0];             var itemdiv = document.createelement("div");             itemdiv.textcontent = "yadda";             firstdiv.appendchild(itemdiv);              itemdiv.addeventlistener("click", follow);          }          function follow()         {             console.log("follow");             polymer.fire("custom-event");         }          polymer({             is: 'x-custom',             ready: init         });      })();     </script> </dom-module> 

it tells me polymer has no function fire. what's correct way call method? anti-patterns here too...

there no fire method inside of polymer object. fire method inside polymer.base, can't use directly unless declare prototype, hence need this. can view polymer properties , methods opening dev tools , typing polymer followed dot.

in summary should use this.fire.

<dom-module id="x-custom">     <template>         <content></content>         <!-- used way <x-custom><div></div></x-custom> -->     </template>      <script>     (function() {          function init() {             var myroot = polymer.dom(this);             var firstdiv = myroot.queryselectorall("div")[0];             var itemdiv = document.createelement("div");             itemdiv.textcontent = "yadda";             firstdiv.appendchild(itemdiv);              itemdiv.addeventlistener("click", follow.bind(this));  // notice .bind here          }          function follow()         {             console.log("follow");             this.fire("custom-event");         }          polymer({             is: 'x-custom',             ready: init         });      })();     </script> </dom-module> 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -