1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

How to get caret position for a contenteditable 'div' in Angular 2?

Discussão em 'Angular' iniciado por swapp1990, Outubro 9, 2024 às 19:23.

  1. swapp1990

    swapp1990 Guest

    I have the following code:

    <div #test (click)="onClick(test)" contenteditable="true">
    This text can be edited by the user.
    </div>

    @ViewChild('test') el:ElementRef;

    constructor(private elementRef: ElementRef) {}

    onClick(event) {
    console.log(this.el.nativeElement);
    let cursor = this.el.nativeElement.selectionStart; //gives undefined
    }


    How do I get the cursor position for the 'div' element when user clicks on the text?

    Continue reading...

Compartilhe esta Página