Я создал функцию в файле global.function.js как
function getData(flag) {
if (flag === 1) {
return "one";
}
else {
return "not one";
}
}
который затем импортируется с помощью элемента custom-js-import.html:
<script src="global.function.js"></script>
Когда я попытался получить доступ к указанной выше функции в custom-element.html, я смог получить к ней доступ в части скрипта, но не в части шаблона. Есть ли способ получить доступ к функции внутри элемента HTML?
<!-- custom-element.html -->
<link rel="import" href="https://polygit.org/components/polymer/polymer-element.html">
<link rel="import" href="custom-js-import.html">
<dom-module id="custom-element">
<template>
<div>
Hello
</div>
<div id="data"></div>
<div>{{getData(1)}}</div><!-- Unable to access this from here -->
<div>{{getLocalData()}}</div>
</template>
<script>
// Define the class for a new element called custom-element
class CustomElement extends Polymer.Element {
static get is() { return "custom-element"; }
constructor() {
super();
}
ready(){
super.ready();
this.$.data.textContent = "I'm a custom-element.";
console.log(getData(1));//can be easily accessed from here
}
getLocalData(){
return "local";
}
}
// Register the new element with the browser
customElements.define(CustomElement.is, CustomElement);
</script>
</dom-module>