我知道这个主题已经有其他问题了,但是没有一个答案特别有帮助,有些已经过时了,所以我想再次询问。
有人成功地使Polymer和Typescript配合使用吗?看起来很接近了,理想情况下我们想要向Polymer提供一个类实例或原型,然后它会处理剩下的事情。
例如,给定以下内容:
<link rel="import" href="../bower_components/polymer/polymer.html">
<polymer-element name="my-element" attributes="color">
<template>
Hello there <strong>{{name}}</strong>
<button on-click="{{setFocus}}">Set focus to text input</button>
</template>
<script src="my-element.js"></script>
</polymer-element>
如果我们这样做:
class MyElement {
name = "Mike";
setFocus() {
console.log("called");
}
}
Polymer(new MyElement());
然后我们成功输出了 "name",但是点击按钮没有调用函数。
但是如果我们这样做:
class MyElement {
name = "Mike";
setFocus() {
console.log("called");
}
}
Polymer(MyElement.prototype);
当我们点击按钮时,会得到控制台输出,但该变量未定义。有人知道如何让它们正常工作吗?