我有一个用打字稿编写的模块,我试图避免在$元素上使用强制转换。
我想声明一个足够类型的模块变量来保存DOM引用。
但是,我无法在元素生命周期中找到正确的位置来执行此操作。请使用我的当前代码查看下面的代码:
static get properties() {
return {
value: {
type: Number,
observer: "valueObserver"
},
}
}
ready() {
// this.element = this.$.id as HTMLInputElement;
// this will fail .... $ is undefined
super.ready();
this.element = this.$.id as HTMLInputElement;
// this is useless.... the observer has already been called
}
valueObserver() {
// I am using this:
(<any>this.$.id).value = this.value;
// I am trying to use instead:
this.element.value = this.value;
// but it will fail, this.element has not been asigned
}