[英]Angular material design valid/invalid input
Couldn't seem to find a relative existing answer so.. 似乎找不到相对的现有答案。
I am using angular material design and i'm creating a sign in/up form. 我正在使用棱角材质设计,并且正在创建签到/签到表格。 At the moment when no text is entered into the field the label and bottom border turns red; 在此字段中未输入任何文本时,标签和底部边框变为红色; this is the result of ng-required="true"
. 这是ng-required="true"
。
I would also like it to turn green when the information is valid, I am not amazingly familiar with angular so not sure if there is another directive I could use? 当信息有效时,我也希望它变绿。我对angular不太熟悉,因此不确定是否可以使用其他指令?
Alternatively I assume some CSS would do the trick; 另外,我假设某些CSS可以解决问题。 In one of my CSS files there is - 在我的CSS文件之一中-
.ng-invalid.ng-dirty {
border-color: #FA787E; (red)
}
.ng-valid.ng-dirty {
border-color: #78FA89; (green)
}
These would be perfect but attached attaching the class does not seem to work (or im doing it wrong) 这些将是完美的,但是附加附加的类似乎不起作用(或者我做错了)
Here is the code from one line of input 这是一行输入中的代码
<md-input-container>
<label class="userlabel">Username</label>
<input ng-model="credentials.username" type="text" ng-required="true" aria-label="password" class="inputtext ng-valid">
</md-input-container>
If anyone could assist that would be great, thanks in advance 如果有人可以帮助,那就太好了,在此先感谢
You are on the right track with the css just missing the .md-input
like this 您正.md-input
正确的轨道.md-input
,而CSS只是像这样缺少.md-input
.md-input.ng-invalid.ng-dirty {
border-color: #FA787E;
}
.md-input.ng-valid.ng-dirty {
border-color: #78FA89;
}
jsfiddle jsfiddle
alternately you can use !important
with you current css border-color
like this border-color: #FA787E !important;
或者,您可以对当前的CSS border-color
使用!important
,例如以下border-color: #FA787E !important;
<md-input-container>
<label class='userlabel'>Username</label>
<input ng-model='credentials.username' type='text' aria-label="password" class="inputtext" required>
</md-input-container>
I took out the ng-required, and placed required in the input tag. 我取出了ng必需的,并把它放在了输入标签中。 So, by default, this input tag will make as ng-invalid. 因此,默认情况下,此输入标签将变为ng-invalid。 Let me know if this works. 让我知道这个是否奏效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.