ViewChild and focus()

Discussão em 'Angular' iniciado por Lempkin, Dezembro 19, 2024.

  1. Lempkin

    Lempkin Guest

    I have a component which contains a textarea which is hidden by default :

    <div class="action ui-g-2" (click)="toggleEditable()">edit</div>
    <textarea [hidden]="!whyModel.inEdition" #myname id="textBox_{{whyModel.id}}" pInputTextarea focus="true" [(ngModel)]="whyModel.description"></textarea>


    When I click on the "edit" div I want to show the textarea and put focus on it :

    @ViewChild('myname') input: ElementRef;
    ...
    private toggleEditable(): void {
    this.whyModel.toggleEditable();
    this.input.nativeElement.focus();
    }


    The "show" part is working but not the focus part. What do I miss?

    Continue reading...

Compartilhe esta Página