gpt4 book ai didi

angular - 如何在 Angular 2+ 中将 md ElementRef 转换为 HtmlElement

转载 作者:太空狗 更新时间:2023-10-29 17:18:54 26 4
gpt4 key购买 nike

我有

 <input mdInput #try  placeholder="Favorite food" value="Sushi">

然后我在 ts 中得到它

 @ViewChild('try') myText : ElementRef;

现在我需要获取 HtmlElement 函数的方法,我该如何转换它?

我不想这样添加 id="try" 到 mdInput并通过 :

var cel= document.getElementById("try");

最佳答案

myText.nativeElement 将包含对 DOM 元素的引用。将 myText.nativeElement 断言为 HTMLElement:

let domElement = this.myText.nativeElement as HTMLElement;

关于angular - 如何在 Angular 2+ 中将 md ElementRef 转换为 HtmlElement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45658352/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com