admin管理员组文章数量:1289582
Inside a directive
in Angular
I did the following:
let input: HTMLElement = renderer.createElement('input');
renderer.appendChild(this.elem.nativeElement, input);
and when I try to get the value writen inside this input using:
console.log('value', input.value);
I get this error:
Property 'value' does not exist on type 'HTMLElement'.
Although we all now that to get value from input using javascript we do the following:
document.getElementById("searchTxt").value;
and document.getElementById()
return either null or HTMLElement
object:
/** * Returns a reference to the first object with the specified value of the ID or NAME attribute. * @param elementId String that specifies the ID value. Case-insensitive. */ getElementById(elementId: string): HTMLElement | null;
so why I get this error ?!!
Inside a directive
in Angular
I did the following:
let input: HTMLElement = renderer.createElement('input');
renderer.appendChild(this.elem.nativeElement, input);
and when I try to get the value writen inside this input using:
console.log('value', input.value);
I get this error:
Property 'value' does not exist on type 'HTMLElement'.
Although we all now that to get value from input using javascript we do the following:
document.getElementById("searchTxt").value;
and document.getElementById()
return either null or HTMLElement
object:
/** * Returns a reference to the first object with the specified value of the ID or NAME attribute. * @param elementId String that specifies the ID value. Case-insensitive. */ getElementById(elementId: string): HTMLElement | null;
so why I get this error ?!!
Share Improve this question asked Dec 5, 2018 at 14:04 SlimenTNSlimenTN 3,5648 gold badges37 silver badges84 bronze badges 1- Why would you create an input this way ? This kind of issue is usually how you create bad practices : tell us what you are trying to achieve, we'll tell you what you can do to achieve it ! – user4676340 Commented Dec 5, 2018 at 14:09
1 Answer
Reset to default 8Use HTMLInputElement
instead:
let input: HTMLInputElement= renderer.createElement('input');
The HTMLElement interface has no "value" property in it, so you get those .ts errors. The HTMLInputElement interface extends HTMLElement and has a "value" property.
本文标签: javascriptProperty 39value39 does not exist on type 39HTMLElement39Stack Overflow
版权声明:本文标题:javascript - Property 'value' does not exist on type 'HTMLElement' - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741478308a2381015.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论