Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

256
Vistas
increase textarea size according to the size of the text in the angular

Currently the following code is being used to resize the textarea

function autoResize(el){
  while (el.scrollHeight > el.offsetHeight){
    el.rows += 1;
  }
}

but it only resizes when I hover over the textarea

<textarea onmousemove="autoResize(this)"></textarea>

I would like to make it resize automatically when I open the screen that has the textarea. I already tried switching to onload but without success

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

export class TextAreaComponent extends OnInit { 
 @ViewChild('textarea', { read: ElementRef,static:true }) textarea: ElementRef; 
  @Input() value:string;
  rowCount: number;
  ngOnInit(): void {
    this._autoResize(this.textarea.nativeElement);
  }

  onKeyup(el) {
    this._autoResize(el);
  }
  private _autoResize(el) {
   while (el.scrollHeight > el.offsetHeight){
     el.rows += 1;
   }
  }  
}

and template of textarea component might be look like this

<textarea
  #textarea
  [value]="!value ? '' : value"
  (keyup)="onKeyup(textarea)"
></textarea>

I have created some sample code for you. https://stackblitz.com/edit/angular-ivy-kxszjh?file=src%2Fapp%2Fapp.component.ts

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda