离子3 textarea的自动调整大小(未离子textarea的)

问题描述 投票:0回答:1

我需要<textarea>的自动调整大小(弹性)。我需要使用<textarea>的,不能使用<离子textarea>的其他问题。

我在下面:How to autoresize the ion-input field vertically while i am typinghttps://stackblitz.com/edit/expandable-input

<离子textarea>的工作:

@Directive({ selector: 'ion-textarea[autosize]' })

但是,不为<textarea>的

@Directive({ selector: 'textarea[autosize]' })

这里是我的Stackblitz(自动调整不工作):https://stackblitz.com/edit/expandable-input-htjncw

控制台错误信息:“错误类型错误:无法读取属性未定义的‘风格’......”

码:

adjust():void {
    const textArea = this.element.nativeElement.getElementsByTagName('textarea')[0];
    textArea.style.overflow = 'hidden';
    textArea.style.height = 'auto';
    textArea.style.height = textArea.scrollHeight + 'px';
  }
ionic3 textarea autosize
1个回答
0
投票

如果要添加的指令textarea代替离子textarea的,您可以直接从nativeElement可以访问HTML元素。你不会通过getElementsByTagName进行访问

adjust():void {
    const textArea = this.element.nativeElement;
    textArea.style.overflow = 'hidden';
    textArea.style.height = 'auto';
    textArea.style.height = textArea.scrollHeight + 'px';
}
© www.soinside.com 2019 - 2024. All rights reserved.