Polymer 2.0 calling functions

I have question about publishing/ building element in Polymer 2.0

I make polymer 2 application using bower. Then I coded my element. I can use it in this project when i call <my-element></my-element> in index.html.

In my Polymer class i have some functions. What should I do in my new project where I will import my builded element <my-element></my-element> to call this functions? For example I will have some file form.html, and in this i will have <my-element></my-element> . What I should do in <script></script> to call for example my-element.myFunction(); ?


absolutely the same as you do in all other elements. Are you using some paper-elements in your project? are you calling some functions on them?

Let's say you have element

<my-element id="myElement"></my-element>

and then in <script> tag

this.$.myElement.someFunction();

imagine your element as some Wrapper for all functions and properties. Defining <my-element> in your code creates instance of it and then through DOM you need to get to it. Normaly in HTML you do document.getElementById("someID") but here, in polymer (if you are using shadow-dom) you just need to do this.getElementById("someID") or in shorthand this.$.someID . So first step is get that element and second is to call function or property. this.$.someID.someFunction()

First, you need to understand some basics of polymer. Try the starting tutorial on polymer. And don't forget that all elements you create, behave absolutely same way as polymer's elements. Your element will have just different styling, functions and properties

链接地址: http://www.djcxy.com/p/5332.html

上一篇: 材料组件Web和Polymer 2.0是否互斥?

下一篇: 聚合物2.0调用函数