MCPcopy Create free account
hub / github.com/angular/components / ngAfterViewInit

Method ngAfterViewInit

src/cdk/text-field/autosize.ts:155–178  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

153 }
154
155 ngAfterViewInit() {
156 if (this._platform.isBrowser) {
157 // Remember the height which we started with in case autosizing is disabled
158 this._initialHeight = this._textareaElement.style.height;
159 this.resizeToFitContent();
160
161 this._ngZone.runOutsideAngular(() => {
162 this._listenerCleanups = [
163 this._renderer.listen('window', 'resize', () => this._resizeEvents.next()),
164 this._renderer.listen(this._textareaElement, 'focus', this._handleFocusEvent),
165 this._renderer.listen(this._textareaElement, 'blur', this._handleFocusEvent),
166 ];
167 this._resizeEvents.pipe(auditTime(16)).subscribe(() => {
168 // Clear the cached heights since the styles can change
169 // when the window is resized (e.g. by media queries).
170 this._cachedLineHeight = this._cachedPlaceholderHeight = undefined;
171 this.resizeToFitContent(true);
172 });
173 });
174
175 this._isViewInited = true;
176 this.resizeToFitContent(true);
177 }
178 }
179
180 ngOnDestroy() {
181 this._listenerCleanups?.forEach(cleanup => cleanup());

Callers

nothing calls this directly

Calls 3

resizeToFitContentMethod · 0.95
listenMethod · 0.80
nextMethod · 0.45

Tested by

no test coverage detected