How to get cursor position in Ionic 4?

In Ionic v3 I did something like this to get cursor position: for iOS textArea._native.nativeElement.selectionStart and for Android but it seems like I cannot find selectionStart on elementRef.

I tried to access element using

@ViewChild('txArea', { read: ElementRef }) textArea: ElementRef;


    (keyup)="onKeyUp($event, txArea)"
    autocorrect="on" autocomplete="on"
    placeholder="Enter description (i.e. @JoeDoe, #forehand)">

Can somebody help with this?


Try to use autofocus in the input tag.

<ion-input autofocus></ion-input>

Another way to do it is:

In the HTML file put it:

<ion-input #input>

In the TS file do it:
export class LoginPage implements AfterViewInit {

  @ViewChild('input')  inputElement: IonInput;

  ngAfterViewInit() {
      setTimeout(() => {
    }, 400);