import { CdkTextareaAutosize } from '@angular/cdk/text-field' ; import { Component , NgZone , ViewChild } from '@angular/core' ; import { take } from 'rxjs/operators' ; title @ Component ( { selector : 'text-field-autosize-textarea-example' , templateUrl : './text-field-autosize-textarea-example.html' , styleUrls : [ './text-field-autosize-textarea-example.css' ] , } ) export class TextFieldAutosizeTextareaExample { constructor ( private ngZone ) { } @ ViewChild ( 'autosize' ) autosize : CdkTextareaAutosize ; triggerResize ( ) { this . ngZone . onStable . pipe ( take ( 1 ) ) . subscribe ( ( ) => this . autosize . resizeToFitContent ( true ) ) ; } }