After developing a textarea component that automatically focuses itself when created using the ngAfterViewInit() method, everything seemed to be working perfectly as expected.
ngAfterViewInit() {
if(this.text.length===0){
this.theinput.setFocus();
}
}
The implementation was straightforward - I used ElementRef to access the ion-textarea component:
@ViewChild('name') theinput: ElementRef;
<ion-textarea #name rows="1" ></ion-textarea>
However, upon running ionic serve
and building the app, an error popped up:
"Property 'setFocus' does not exist on type 'ElementRef'."
This issue occurred at the line of code where this.theinput.setFocus()
was called.
A temporary fix involved commenting out the problematic line, rebuilding the app, and then uncommenting it. This solution worked but was not ideal.
Seeking a more efficient workaround, one possible solution could involve extending ElementRef or exploring similar alternatives?