【发布时间】:2019-06-27 22:52:35
【问题描述】:
我需要
我在关注:How to autoresize the ion-input field vertically while i am typing & https://stackblitz.com/edit/expandable-input
@Directive({ selector: 'ion-textarea[autosize]' })
但是,不适用于
@Directive({ selector: 'textarea[autosize]' })
这是我的 Stackblitz(自动调整大小不起作用):https://stackblitz.com/edit/expandable-input-htjncw
控制台错误:“ERROR TypeError: Cannot read property 'style' of undefined ...”
代码:
adjust():void {
const textArea = this.element.nativeElement.getElementsByTagName('textarea')[0];
textArea.style.overflow = 'hidden';
textArea.style.height = 'auto';
textArea.style.height = textArea.scrollHeight + 'px';
}
【问题讨论】:
-
请在此处提供minimal reproducible example。不是链接
-
你会从
this.element.nativeElement得到textarea,因为你没有使用离子组件。