简体   繁体   English

角材料输入占位符颜色更改(如果存在输入值)

[英]Angular material input placeholder color change if input value exists

I am using angular 5 with material 5.2. 我在材质5.2中使用了角度5。 I want to change the input field placeholder colour If field is not empty. 我想更改输入字段占位符颜色如果字段不为空。 I can able to change the colour when I focused on field, but not able to change the colour if value exists. 当我专注于字段时,我可以更改颜色,但是如果值存在,则不能更改颜色。

I have tried below code. 我试过下面的代码。 Its changing all the fields empty and non empty fields. 它更改所有字段为空和非空字段。 I want to change the colour only non empty fields. 我只想更改非空字段的颜色。 Please advice me 请告诉我

::ng-deep .mat-form-field-placeholder{
 color:#2196F3
 }
 ::ng-deep .mat-focused .mat-form-field-placeholder{
  color:#2196F3;
   }
 ::ng-deep .mat-form-field-underline .mat-form-field-ripple{
    background-color:#2196F3;
    }
 ::ng-deep .mat-form-field-underline{
 background-color:#2196F3;
  }

After some research found the below solution. 经过一番研究发现以下解决方案。 I have added 我已经添加了

 <mat-label style="blue">UserName</mat-label>

the floating label is a text label displayed on top of the form field control when the control does not contain any text. 浮动标签是当控件不包含任何文本时显示在表单字段控件顶部的文本标签。 By default, when text is present the floating label floats above the form field control. 默认情况下,当出现文本时,浮动标签将浮动在表单字段控件上方。 The label for a form field can be defined either through a mat-label element, by setting the placeholder attribute on the form control or using the mat-placeholder element. 可以通过mat-label元素,通过在表单控件上设置占位符属性或使用mat-placeholder元素来定义表单字段的标签。 If there are multiple clashing values (eg a placeholder and a label) the mat-label will take precedence and the placeholder will be shown only when there is no value. 如果存在多个冲突值(例如,占位符和标签),则以mat-label为准,并且仅当无值时才显示占位符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM