我正在尝试创建一个input
至少在宽度上随着用户输入的字符串的长度动态扩展的字段,甚至可能是多行的。
这可能吗?input https://material.angular.io/components/input/overviewAngular Material 2 中的元素?
随着textarea
来自 Angular Material 2 的字段我只能使用以下代码扩展文本区域的高度,而不是宽度:
<mat-form-field (keydown.enter)="onEnter()"
floatPlaceholder="never">
<textarea matInput
placeholder="Autosize textarea"
matTextareaAutosize
matAutosizeMinRows="1"
matAutosizeMaxRows="8">
</textarea>
</mat-form-field>
也在 StackBlitz 上 https://stackblitz.com/edit/angular-3ikrwd?file=app%2Finput-autosize-textarea-example.html.
In case of the textarea
the scrollbar
should be invisible or replaced by a smaller one. And most important pressing Enter should not create a new line but trigger an action only.
简单且唯一的模板解决方案:
<mat-form-field
[ngStyle]="{'width.ch': inputText.value.length, 'min-width.ch': 10}">
<input #inputText matInput>
</mat-form-field>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)