1 // Thanks: https://github.com/evseevdev/ngx-textarea-autosize
2 import { AfterViewInit, Directive, ElementRef, HostBinding, HostListener } from '@angular/core'
5 selector: 'textarea[myAutoResize]'
7 export class TextareaAutoResizeDirective implements AfterViewInit {
8 @HostBinding('attr.rows') rows = '1'
9 @HostBinding('style.overflow') overflow = 'hidden'
11 constructor (private elem: ElementRef) { }
13 public ngAfterViewInit () {
17 @HostListener('input')
19 const textarea = this.elem.nativeElement as HTMLTextAreaElement
20 // Reset textarea height to auto that correctly calculate the new height
21 textarea.style.height = 'auto'
23 textarea.style.height = `${textarea.scrollHeight}px`