import { ElementRef , HostListener , Directive } from '@angular/core' ; @ Directive ( { selector : 'textarea[autosize]' } ) export class Autosize { @ HostListener ( 'input' , [ '$event.target' ] ) onInput ( textArea ) { this . adjust ( ) ; } constructor ( public element ) { } ngAfterContentChecked ( ) { this . adjust ( ) ; } adjust ( ) { this . element . nativeElement . style . overflow = 'hidden' ; this . element . nativeElement . style . height = 'auto' ; this . element . nativeElement . style . height = this . element . nativeElement . scrollHeight + "px" ; } }