Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

247
Views
aumentar el tamaño del área de texto de acuerdo con el tamaño del texto en el angular

Actualmente, el siguiente código se está utilizando para cambiar el tamaño del área de texto

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

pero solo cambia de tamaño cuando paso el cursor sobre el área de texto

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

Me gustaría hacer que cambie de tamaño automáticamente cuando abro la pantalla que tiene el área de texto. Ya intenté cambiar a onload pero sin éxito

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

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; } } }

y la plantilla del componente textarea podría verse así

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

He creado un código de muestra para ti. https://stackblitz.com/edit/angular-ivy-kxszjh?file=src%2Fapp%2Fapp.component.ts

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!