0

我正在开发一个角度应用程序,其中我有一个 matInput,我试图在 matInput 的占位符中显示一个图标。我尝试使用的字体真棒图标是 info-circle My Code

<mat-form-field>
    <input matInput
            class = "fas"
            placeholder= "&#xf05a;Default Value"
            [(ngModel)]="Value"
            style="font-family: Arial, 'Font Awesome'">
</mat-form-field>

使用此代码,我可以看到一个图标,但它没有按预期出现。 在此处输入图像描述

我已经交叉检查了图标代码及其正确性。我不确定出了什么问题。

4

2 回答 2

0

我不确定这是否有效。我认为您需要在表单字段中添加一个 mat-icon 并将其标记为 matPrefix:

<mat-form-field>
  <mat-label>A Label</mat-label>
  <input matInput placeholder="Placeholder">
  <mat-icon matPrefix>sentiment_very_satisfied</mat-icon>
</mat-form-field>

见文档:material.angular.io/components/form-field/api

于 2020-10-19T05:38:36.873 回答
0

你可以这样做——

在您的 HTML-

<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet"/>
    <div class="input-wrapper">
       <mat-form-field>
       <input matInput
                class = "fas"                       
                >
      <label for="stuff" class="fa fa-info-circle"></label>
      </mat-form-field>
    </div>

在你的 CSS-

.fa-info-circle{
  position: absolute;
  left: 3px;
  top: calc(50% - 0.5em); /* Keep icon in center of input, regardless of the input height */
}

::placeholder {
  text-align: center;
}
.input-wrapper{
  position: relative;
}
于 2020-10-19T06:04:54.030 回答