【问题标题】:Mat-input Placeholder position垫输入占位符位置
【发布时间】:2020-04-12 12:01:48
【问题描述】:

我正在使用 mat-input 构建表单,但输入占位符位置不正确。如何设置占位符位置?

这是我的html:

<mat-form-field [hideRequiredMarker]="formTclimit.value.hideRequired" [floatLabel]="formTclimit.value.floatLabel" style="width:97%">
<div class="inputborder" [ngClass]="{'inputerror':formTclimit.controls['codename'].invalid && formTclimit.controls['codename'].touched}">
<img class="search" />
<input style="display: inline-block;" type="text" matInput formControlName="codename" placeholder="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{'placeholder.search'|translate}}" (click)="searchStation()" [matAutocomplete]="tclstation">
<img class="required" />
</div>
</mat-form-field>

我从不使用 floatLabel 值。

有什么想法吗?

提前致谢!

更新:

我也试过了,@JuNe 建议的选项,但我遇到了类似的问题:

我的html是:

<mat-form-field class="inputborder" [ngClass]="{'inputerror':formTclimit.controls['codename'].invalid && formTclimit.controls['codename'].touched}" [hideRequiredMarker]="formTclimit.value.hideRequired" [floatLabel]="formTclimit.value.floatLabel" style="width:97%;vertical-align: top!important">
 <mat-label class="matlabel"> 
     <img class="search" /> 
     <span>{{'placeholder.search'|translate}}</span> 
</mat-label> 
<input style="display: inline-block; width:80%!important; padding:5px" type="text" matInput formControlName="codename" (click)="searchStation()" [matAutocomplete]="tclstation"> <img class="required" /> <button class="float-right button-esc" style="margin-top:5px!important" (click)="formTclimit.controls['codename'].value=''"><img class="remove"/></button> 

问题类似,matlabel 添加了红色边框,但我不知道 mat-label 下方是什么或如何将 mat-label 移动到顶部。

有什么想法吗?

谢谢!

【问题讨论】:

  • 你能用最少的代码分享 stackblitz 来重现这个问题吗?

标签: angular angular-material placeholder mat-input


【解决方案1】:

您可以使用mat-label 标签代替输入的占位符属性。然后您应该能够设置占位符文本的样式。

<mat-form-field>
  <mat-label class="some">Placeholdertext</mat-label>
  <input matInput type="text"/>
</mat-form-field>

【讨论】:

  • 嗨@JuNe!感谢您的回答!我尝试使用 mat-label 但现在我遇到了同样的问题。类似乎不适用于 mat-label
猜你喜欢
  • 2017-05-11
  • 2017-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-01
  • 2011-07-28
相关资源
最近更新 更多