gpt4 book ai didi

javascript - 如何初始化 ElementRef Angular - typescript

转载 作者:行者123 更新时间:2023-12-05 00:28:09 79 4
gpt4 key购买 nike

当我使用@ViewChild('serachField', { static: false }) serachField: ElementRef<HTMLInputElement>我得到错误

Property 'serachField' has no initializer and is not definitely assigned in the constructor.
我通常初始化变量,但我不确定在这种情况下如何做
我试过了
@ViewChild('serachField', { static: false }) serachField: ElementRef<HTMLInputElement> = new ElementRef<HTMLInputElement>(--unsure what the parameter should be--)
我得到:
Expected 1 arguments, but got 0.ts(2554)
core.d.ts(2253, 17): An argument for 'nativeElement' was not provided.

最佳答案

谢谢@Isbn
我用了:

@ViewChild('serachField', { static: false }) serachField: ElementRef<HTMLInputElement> = {} as ElementRef;

关于javascript - 如何初始化 ElementRef Angular - typescript ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68002447/

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