简体   繁体   English

angular 素材-输入提交后更改输入下划线颜色

[英]angular material - change input underline color after input is submitted

I'm trying to change the color of mat-input-underline: first: the line is grey and its ok enter image description here我正在尝试更改 mat-input-underline 的颜色:首先:这条线是灰色的,可以在此处输入图像描述

second: on focus the line is purple and its ok enter image description here第二:对焦线是紫色的,可以在此处输入图像描述

at the end the underline color return to be black after focus on other field.最后下划线颜色在关注其他字段后恢复为黑色。

i want that after focus the color will remain purple.我希望在对焦后颜色将保持紫色。

how do i do it?我该怎么做?

thanks谢谢

For each mat input: on focus gain, set a boolean hadFocus to true.对于每个垫子输入:在焦点增益上,将 boolean hadFocus 设置为 true。 Use a [class.had-focus]="hadFocus" directive on your mat input element and apply the "purple" styles in your CSS to the.had-focus class.在垫子输入元素上使用 [class.had-focus]="hadFocus" 指令,并将 CSS 中的“紫色” styles 应用于.had-focus ZA2F2ED4F8EBC2CBB4C21A29DC40AB61D。

You might think you can do that using a form control's pristine field.您可能认为可以使用表单控件的原始字段来做到这一点。 But if I remember correctly, the pristine field will reset automatically at some point.但如果我没记错的话,原始场会在某个时候自动重置。 You can give it a try though.不过你可以试一试。

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

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