Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/408.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当用户输入换行符时,如何强制Textarea增加高度?_Javascript_Angular_Angular Material_Textarea - Fatal编程技术网

Javascript 当用户输入换行符时,如何强制Textarea增加高度?

Javascript 当用户输入换行符时,如何强制Textarea增加高度?,javascript,angular,angular-material,textarea,Javascript,Angular,Angular Material,Textarea,问题的。 从这里得到帮助。我用它来调节高度;当输入超过107个字符时,它将从3行扩展到5行。之后,它添加了一个滚动条,用户可以滚动其余的内容 我的要求是,当用户 把一条线打断。如果用户输入1,然后按enter键,然后输入2,然后输入3,然后在下一次输入时再次输入,则应调整第4行的大小并增加其高度。我该怎么做 从'@angular/core'导入{Component,ElementRef,ViewChild}; /** *@title基本输入 */ @组成部分({ 选择器:“输入概述示例”, 风格

问题的

从这里得到帮助。我用它来调节高度;当输入超过107个字符时,它将从3行扩展到5行。之后,它添加了一个滚动条,用户可以滚动其余的内容

我的要求是,当用户 把一条线打断。如果用户输入1,然后按enter键,然后输入2,然后输入3,然后在下一次输入时再次输入,则应调整第4行的大小并增加其高度。我该怎么做

从'@angular/core'导入{Component,ElementRef,ViewChild};
/**
*@title基本输入
*/
@组成部分({
选择器:“输入概述示例”,
风格:`
::ng deep.commentText{
宽度:100%!重要;
最小高度:59px;
最大高度:100px;
边界半径:4px!重要;
边框:实心1px#bab8b8!重要;
字体大小:13px;
颜色:#000000;
填充:6px;
调整大小:无;
}
`,
模板:'
',
})
导出类InputOverview示例{
@ViewChild('commentTextArea',{static:false})commentTextArea:ElementRef;
文本区域高度:任意;
commentTextValue:字符串;
textAreaResize(){
//this.changeDetectorRef.detectChanges();
const textArea:HTMLTextAreaElement=this.commentTextArea.nativeElement;
if(this.commentTextValue | | this.commentTextValue===“”){
if(this.commentTextValue.length<107){
this.textAreaHeight='59px';
}否则{
const height=Math.max(57,Math.min(textArea.scrollHeight,98));
textArea.style.overflow=(textArea.scrollHeight>height?'auto':'hidden');
this.textAreaHeight=高度+px;
}
}
}
}
/**2019谷歌公司版权所有。保留所有权利。
此源代码的使用受MIT风格的许可证管理,该许可证
可以在以下位置的许可证文件中找到:http://angular.io/license */

在文本区域上使用
cdkTextareaAutosize
decorator,通过输入或换行来增加高度

<textarea class="commentText"
     #commentTextArea
     cdkTextareaAutosize
     [style.height]="textAreaHeight"
     (input)="textAreaResize()"
     [maxLength]="300"
     [(ngModel)]="commentTextValue"
     placeholder="Type your Comment">
</textarea>

<textarea class="commentText"
     #commentTextArea
     cdkTextareaAutosize
     [style.height]="textAreaHeight"
     (input)="textAreaResize()"
     [maxLength]="300"
     [(ngModel)]="commentTextValue"
     placeholder="Type your Comment">
</textarea>