How to change Angular 5 Material input placeholder

2019-04-27 13:49发布

How do you change the placeholder colour on a angular/material input placeholder?

<mat-form-field>
    <input matInput placeholder="Name">
  </mat-form-field>

8条回答
倾城 Initia
2楼-- · 2019-04-27 14:19

One solution provided by material 2 itself found in example code. I have done a sample here:

 <mat-form-field>
   <mat-label>Input</mat-label>
   <input matInput >
 </mat-form-field>

Plunker

查看更多
再贱就再见
3楼-- · 2019-04-27 14:21

What options we have?

  1. <mat-placeholder> tag is deprecated: https://material.angular.io/components/form-field/api#MatPlaceholder

  2. /deep/ selector will be deprecated soon. ::placeholder selector is still experimental feature: https://developer.mozilla.org/en-US/docs/Web/CSS/::placeholder

So I would recommend to use input placeholder as an attribute only if your clients have modern browsers.

查看更多
登录 后发表回答